-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
refactor(es/parser): detach swc_ecma_parser from swc_emca_lexer
#11148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
8aef46c to
d856923
Compare
CodSpeed Performance ReportMerging #11148 will degrade performances by 5.32%Comparing Summary
Benchmarks breakdown
Footnotes
|
This comment was marked as spam.
This comment was marked as spam.
809252f to
0420eb6
Compare
784b3e9 to
9e34964
Compare
cd20ed2 to
d3b79fc
Compare
d3b79fc to
236f45e
Compare
This reverts commit ec916c6.
Background:
In #10377 and #10399, we create another crate
swc_ecma_lexerfromswc_ecma_parser.TokenKindandTokenValueto make lexer and parser run faster. This has been done inswc_ecma_parser, whoseTokenis only 1 byte. This also means we should refactor the lexer and the parser.LexerandTokenpublic, so the change ofTokenwill introduce a large breaking for rust users. So for compatibility, we have to keep the legacy set of lexer and parser to produce compatibleTokens.swc_ecma_lexer/commonby introducing a set of complexyParseTrait,LexerTrait, etc, which makes the project chaotic and less comprehensive. You can see thatswc_ecma_parserdepends onswc_ecma_lexerand calls the common functions everywhere.Motivation:
Description:
Now it's time to correct the decision. This pr makes
swc_ecma_parserself-contained and doesn't dependsswc_ecma_lexerany more. On the contrary, this pr makesswc_ecma_lexerdepends on someswc_ecma_parserinstead such as some common simple data structure likeSyntax. For compatibility, I also move and import legacyTokeninswc_ecma_parser.After this pr the
swc_ecma_lexeris nearly marked as no longer maintained. All the bug fixes and performance optimization should only be applied inswc_ecma_parser.Specifically, what I do in this pr is only copy all common functions from
swc_ecma_lexer/commontoswc_ecma_parserand eliminate the trait-based generics. For example:Note that I nearly doesn't change anything in
swc_ecma_lexerso the lexer and parser in that crate are still based on trait and common function.Breaking Changes:
If you don't use
TokenAPI, then there's no breaking changes, which means for most rust api users, there's no breaking change. Otherwise you may need to remove the dependencies ofswc_ecma_lexerand related imports of traits.Test in community crates:
swc_ecma_lexerand related imports of traits.Future Works:
Actually when I finished copying all the code, the performance got regression. It takes me lots of time to figure it out but I finally keep the regression around -1%. So I have to do some complex optimization ahead of time such as refactor of
parse_subscripts. I think it's better to merge the optimization in other PRs. So after this pr is ready I will split the that off.