Skip to content

perf(transformer): allocate AST nodes in arena directly#23711

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/06-21-perf_transformer_allocate_ast_nodes_in_arena_directly
Jun 23, 2026
Merged

perf(transformer): allocate AST nodes in arena directly#23711
graphite-app[bot] merged 1 commit into
mainfrom
om/06-21-perf_transformer_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.

In transform_ts_import_equals, additionally avoid unnecessarily allocating the string "require" into arena, by using static_ident! instead.

overlookmotel commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

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

✅ 52 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing om/06-21-perf_transformer_allocate_ast_nodes_in_arena_directly (55fd31d) with om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly (b57ac10)2

Open in CodSpeed

Footnotes

  1. 19 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.

  2. No successful run was found on om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly (0090ac3) during the generation of this report, so ea62bb9 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 June 22, 2026 12:44
@overlookmotel overlookmotel requested a review from Dunqing as a code owner June 22, 2026 12:44
Copilot AI review requested due to automatic review settings June 22, 2026 12:44

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, mechanical performance optimizations across the transformer by allocating AST nodes directly into the arena (especially where nodes are immediately boxed), reducing temporary stack allocations/copies, and using more specific AstBuilder helpers.

Changes:

  • Prefer alloc_*/boxed-returning builder APIs and pass ArenaBox values through directly to avoid extra ctx.alloc(...) + moves.
  • Update helper construction (helper_call) and several transforms to return/consume boxed nodes where boxing is inevitable.
  • Avoid allocating "require" into the arena by using static_ident! in TS import-equals lowering.

Reviewed changes

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

Show a summary per file
File Description
tasks/track_memory_allocations/allocs_transformer.snap Updates allocation snapshot to reflect the new arena-allocation behavior.
crates/oxc_transformer/src/typescript/module.rs Uses static_ident! for require, allocates string literal args directly in arena, and builds identifier expressions without clone+alloc.
crates/oxc_transformer/src/typescript/enum.rs Builds enum binding patterns directly with symbol id (avoids clone+alloc path).
crates/oxc_transformer/src/typescript/annotations.rs Allocates identifier references directly into the arena and passes boxed identifiers through.
crates/oxc_transformer/src/jsx/jsx_impl.rs Returns ArenaBox<IdentifierReference> from internal helpers and avoids repeated allocate-then-wrap patterns.
crates/oxc_transformer/src/es2021/logical_assignment_operators.rs Builds identifier expressions directly with known reference_id instead of cloning + arena allocation.
crates/oxc_transformer/src/es2018/object_rest_spread.rs Adjusts helper call usage and variable declaration creation to operate on boxed arena nodes end-to-end.
crates/oxc_transformer/src/decorator/legacy/mod.rs Clones literal/template data directly into the allocator to avoid intermediate allocations.
crates/oxc_transformer/src/common/var_declarations.rs Uses dedicated binding-pattern builder helpers to avoid extra allocation steps.
crates/oxc_transformer/src/common/helper_loader.rs Changes helper_call to return ArenaBox<CallExpression> and allocates the call expression directly in the arena.
crates/oxc_transformer_plugins/src/module_runner_transform.rs Allocates reused binding identifiers into the arena earlier and constructs string literal arguments more directly.

@graphite-app graphite-app Bot force-pushed the om/06-21-perf_minifier_allocate_ast_nodes_in_arena_directly branch from 25120f4 to 644b3d0 Compare June 22, 2026 12:55
@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
@overlookmotel overlookmotel changed the base branch from om/06-21-perf_minifier_allocate_ast_nodes_in_arena_directly to graphite-base/23711 June 22, 2026 12:56
@overlookmotel overlookmotel force-pushed the om/06-21-perf_transformer_allocate_ast_nodes_in_arena_directly branch from ca1a2ae to 8d8dbf2 Compare June 22, 2026 12:56
@overlookmotel overlookmotel changed the base branch from graphite-base/23711 to om/06-21-perf_parser_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
@overlookmotel overlookmotel force-pushed the om/06-21-perf_transformer_allocate_ast_nodes_in_arena_directly branch from 8d8dbf2 to a231889 Compare June 22, 2026 14:59
@graphite-app

graphite-app Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Merge activity

Same as #23709.

Small perf optimizations around AST builder calls.

- AST nodes which end up in `Box`es, 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.

In `transform_ts_import_equals`, additionally avoid unnecessarily allocating the string `"require"` into arena, by using `static_ident!` instead.
@graphite-app graphite-app Bot force-pushed the om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly branch from 0090ac3 to 1c63c66 Compare June 23, 2026 01:01
@graphite-app graphite-app Bot force-pushed the om/06-21-perf_transformer_allocate_ast_nodes_in_arena_directly branch from 55fd31d to 680ffbc Compare June 23, 2026 01:02
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jun 23, 2026
Base automatically changed from om/06-21-perf_parser_allocate_ast_nodes_in_arena_directly to main June 23, 2026 01:06
@graphite-app graphite-app Bot merged commit 680ffbc into main Jun 23, 2026
31 checks passed
@graphite-app graphite-app Bot deleted the om/06-21-perf_transformer_allocate_ast_nodes_in_arena_directly branch June 23, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants