Skip to content

perf(parser): allocate AST nodes in arena directly#23712

Open
overlookmotel wants to merge 1 commit into
om/06-21-perf_minifier_allocate_ast_nodes_in_arena_directlyfrom
om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly
Open

perf(parser): allocate AST nodes in arena directly#23712
overlookmotel wants to merge 1 commit into
om/06-21-perf_minifier_allocate_ast_nodes_in_arena_directlyfrom
om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jun 22, 2026

Copy link
Copy Markdown
Member

Same as #23709.

Small perf optimizations around AST builder calls.

  • AST nodes which end up in Boxes, allocate into the Box as early as possible, to increase chance compiler sees the type can be built directly in arena, rather than built on the stack, and then copied from stack into arena.
  • Functions return Box<T> rather than T where the value needs to be boxed anyway. If function is not inlined, this avoids stack allocation + copy.

Also, shorten code where possible by using more specific AstBuilder methods.

overlookmotel commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


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 changes, fast-track this PR to the front of 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-hq

codspeed-hq Bot commented Jun 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly (b57ac10) with om/06-21-perf_minifier_allocate_ast_nodes_in_arena_directly (644b3d0)

Open in CodSpeed

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@overlookmotel overlookmotel marked this pull request as ready for review June 22, 2026 12:46
Copilot AI review requested due to automatic review settings June 22, 2026 12:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR applies small performance-focused refactors in oxc_parser to allocate AST nodes directly in the arena (and/or return already-boxed nodes) to reduce intermediate stack allocations and copies during parsing.

Changes:

  • Return Box<'a, T> from several parsing helpers when the produced AST node is always boxed in the AST (e.g. literals, using declarations, TS import attributes object).
  • Replace “build then alloc” patterns with AstBuilder::alloc_* constructors (e.g. alloc_identifier_name, alloc_object_expression, alloc_*_literal).
  • Thread boxed nodes through call sites to avoid extra self.alloc(...) steps.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/oxc_parser/src/ts/types.rs Allocate TS import type option/attribute AST nodes directly in the arena; return boxed object expressions where required.
crates/oxc_parser/src/js/statement.rs Pass already-boxed using declarations into parse_any_for_loop without re-boxing.
crates/oxc_parser/src/js/expression.rs Return boxed literal nodes and construct Expression::*Literal variants without intermediate allocations.
crates/oxc_parser/src/js/declaration.rs Make parse_using_declaration return a boxed VariableDeclaration and propagate that to statement construction.
crates/oxc_parser/src/js/binding.rs Make rest-element parsing return boxed rest elements and pass them through binding-pattern builders directly.
crates/oxc_parser/src/cursor.rs Update parse_delimited_list_with_rest to return an optional boxed rest element to match binding parser changes.

@overlookmotel overlookmotel requested a review from Dunqing June 22, 2026 12:49
@graphite-app graphite-app Bot force-pushed the om/06-21-perf_transformer_allocate_ast_nodes_in_arena_directly branch from c94b543 to ca1a2ae Compare June 22, 2026 12:55
@graphite-app graphite-app Bot force-pushed the om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly branch from 6853db4 to 35f8681 Compare June 22, 2026 12:56
@overlookmotel overlookmotel changed the base branch from om/06-21-perf_transformer_allocate_ast_nodes_in_arena_directly to graphite-base/23712 June 22, 2026 12:56
@overlookmotel overlookmotel force-pushed the om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly branch from 35f8681 to 4149490 Compare June 22, 2026 12:56
@overlookmotel overlookmotel changed the base branch from graphite-base/23712 to om/06-21-perf_minifier_allocate_ast_nodes_in_arena_directly June 22, 2026 12:57
@overlookmotel overlookmotel force-pushed the om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly branch from 4149490 to b57ac10 Compare June 22, 2026 14:59
graphite-app Bot pushed a commit that referenced this pull request Jun 22, 2026
)

Optimization to parsing JSX.

When parsing JSX element names `parse_jsx_element_name` has to determine if the identifier:

1. starts with a lowercase letter, and
2. contains a `-`.

The 2nd check is relatively expensive - string search.

Avoid the search by making the lexer feed this information (which it already has) to the parser. This reduces the check in the parser to just `!contains_dash`.

(came across this while working #23712)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants