Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 4, 2025

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.

@github-actions github-actions bot added A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance labels Aug 4, 2025
Copy link
Member Author

overlookmotel commented Aug 4, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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-hq
Copy link

codspeed-hq bot commented Aug 4, 2025

CodSpeed Instrumentation Performance Report

Merging #12807 will not alter performance

Comparing 08-04-perf_parser_register_import___export_statements_in_module_record_directly (5d96425) with main (83ac93c)1

Summary

✅ 34 untouched benchmarks

Footnotes

  1. No successful run was found on main (febb4fa) during the generation of this report, so 83ac93c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel marked this pull request as ready for review August 4, 2025 14:49
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Aug 5, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 5, 2025

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.
@graphite-app graphite-app bot force-pushed the 08-04-refactor_parser_add_statementcontext_toplevelstatementlist_ branch from 020e6f5 to febb4fa Compare August 5, 2025 07:02
@graphite-app graphite-app bot force-pushed the 08-04-perf_parser_register_import___export_statements_in_module_record_directly branch from b9c79b6 to 5d96425 Compare August 5, 2025 07:02
Base automatically changed from 08-04-refactor_parser_add_statementcontext_toplevelstatementlist_ to main August 5, 2025 07:07
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 5, 2025
@graphite-app graphite-app bot merged commit 5d96425 into main Aug 5, 2025
26 checks passed
@graphite-app graphite-app bot deleted the 08-04-perf_parser_register_import___export_statements_in_module_record_directly branch August 5, 2025 07:09
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants