-
-
Notifications
You must be signed in to change notification settings - Fork 723
perf(parser): register import / export statements in module record directly
#12807
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
perf(parser): register import / export statements in module record directly
#12807
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #12807 will not alter performanceComparing Summary
Footnotes |
Merge activity
|
…d directly (#12807) Currently when parsing a list of statements in `parse_directives_and_statements`, we: 1. Check on every turn of the loop whether the statement is a `ModuleDeclaration`, and whether at top level. 2. If so, we call `ModuleRecordBuilder::visit_module_declaration`. 3. `visit_module_declaration` branches again on the type of the `ModuleDeclaration`. Instead, remove `ModuleRecordBuilder::visit_module_declaration` method, and instead call individual methods of `ModuleRecordBuilder` for each type of declaration directly, when parsing that particular declaration. This removes the need to check *every* statement in the loop in `parse_directives_and_statements` just in case it's a module declaration. Gives a small perf boost (+0.2%) on parser benchmarks. Might be a little bit more in real world, as this removes an unpredictable branch, which CodSpeed doesn't measure.
020e6f5 to
febb4fa
Compare
b9c79b6 to
5d96425
Compare
…12808) We currently store the `default` keyword for `ExportDefaultDeclaration` as a `ModuleExportName`. This is overkill because the name is always, by definition, `default`. The only place the `Span` of `default` keyword is used is in `ModuleRecordBuilder`. So essentially storing the span in AST is using the AST as temporary storage - it's only put there so that `ModuleRecordBuilder` can pull it out again. After #12807, we can just pass the span direct to `ModuleRecordBuilder`, and so remove the need for it to be in the AST at all. So we can remove the whole field. This reduces size of `ExportDefaultDeclaration` from 80 bytes to 24. That has very limited impact, because each file can only have 1 `export default` statement. But still... less is more! It also removes erroneous code in both isolated declarations and transformer, which both just gave the keyword an empty span. I think the fact that everywhere that does use this field uses it wrongly is good justification for its removal! (alternative to #12803)
…d directly (oxc-project#12807) Currently when parsing a list of statements in `parse_directives_and_statements`, we: 1. Check on every turn of the loop whether the statement is a `ModuleDeclaration`, and whether at top level. 2. If so, we call `ModuleRecordBuilder::visit_module_declaration`. 3. `visit_module_declaration` branches again on the type of the `ModuleDeclaration`. Instead, remove `ModuleRecordBuilder::visit_module_declaration` method, and instead call individual methods of `ModuleRecordBuilder` for each type of declaration directly, when parsing that particular declaration. This removes the need to check *every* statement in the loop in `parse_directives_and_statements` just in case it's a module declaration. Gives a small perf boost (+0.2%) on parser benchmarks. Might be a little bit more in real world, as this removes an unpredictable branch, which CodSpeed doesn't measure.
…xc-project#12808) We currently store the `default` keyword for `ExportDefaultDeclaration` as a `ModuleExportName`. This is overkill because the name is always, by definition, `default`. The only place the `Span` of `default` keyword is used is in `ModuleRecordBuilder`. So essentially storing the span in AST is using the AST as temporary storage - it's only put there so that `ModuleRecordBuilder` can pull it out again. After oxc-project#12807, we can just pass the span direct to `ModuleRecordBuilder`, and so remove the need for it to be in the AST at all. So we can remove the whole field. This reduces size of `ExportDefaultDeclaration` from 80 bytes to 24. That has very limited impact, because each file can only have 1 `export default` statement. But still... less is more! It also removes erroneous code in both isolated declarations and transformer, which both just gave the keyword an empty span. I think the fact that everywhere that does use this field uses it wrongly is good justification for its removal! (alternative to oxc-project#12803)

Currently when parsing a list of statements in
parse_directives_and_statements, we:ModuleDeclaration, and whether at top level.ModuleRecordBuilder::visit_module_declaration.visit_module_declarationbranches again on the type of theModuleDeclaration.Instead, remove
ModuleRecordBuilder::visit_module_declarationmethod, and instead call individual methods ofModuleRecordBuilderfor each type of declaration directly, when parsing that particular declaration.This removes the need to check every statement in the loop in
parse_directives_and_statementsjust in case it's a module declaration.Gives a small perf boost (+0.2%) on parser benchmarks. Might be a little bit more in real world, as this removes an unpredictable branch, which CodSpeed doesn't measure.