perf(transformer): allocate AST nodes in arena directly#23711
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
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 passArenaBoxvalues through directly to avoid extractx.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 usingstatic_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. |
25120f4 to
644b3d0
Compare
c94b543 to
ca1a2ae
Compare
ca1a2ae to
8d8dbf2
Compare
4149490 to
b57ac10
Compare
8d8dbf2 to
a231889
Compare
a231889 to
55fd31d
Compare
b57ac10 to
0090ac3
Compare
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.
0090ac3 to
1c63c66
Compare
55fd31d to
680ffbc
Compare

Same as #23709.
Small perf optimizations around AST builder calls.
Boxes, allocate into theBoxas 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.Box<T>rather thanTwhere 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
AstBuildermethods.In
transform_ts_import_equals, additionally avoid unnecessarily allocating the string"require"into arena, by usingstatic_ident!instead.