perf(parser): register import / export statements in module record directly#12807
Merged
graphite-app[bot] merged 1 commit intomainfrom Aug 5, 2025
Conversation
Member
Author
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 |
Contributor
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
Base automatically changed from
08-04-refactor_parser_add_statementcontext_toplevelstatementlist_
to
main
August 5, 2025 07:07
graphite-app bot
pushed a commit
that referenced
this pull request
Aug 5, 2025
…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)
This was referenced Aug 6, 2025
taearls
pushed a commit
to taearls/oxc
that referenced
this pull request
Aug 12, 2025
…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.
taearls
pushed a commit
to taearls/oxc
that referenced
this pull request
Aug 12, 2025
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.