perf(minifier): allocate AST nodes in arena directly#23710
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR applies small performance-oriented refactors in oxc_minifier to build AST nodes directly into arena-allocated Boxes earlier and to use more specific AstBuilder convenience helpers, reducing stack construction/copies and shortening call sites.
Changes:
- Update AST construction call sites to use
alloc_*builder methods directly (e.g., literals, object/block expressions). - Replace manual
BlockStatementboxing patterns withstatement_block_with_scope_id/alloc_block_statementhelpers. - Simplify a minifier test to avoid an unnecessary
clone_inwhen the vector is consumed.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_minifier/tests/ecmascript/array_join.rs | Uses arena-allocating literal/object builders and removes an unnecessary clone_in when constructing the test array AST. |
| crates/oxc_minifier/src/peephole/remove_dead_code.rs | Swaps Box<BlockStatement> directly using alloc_block_statement, avoiding stack construction + re-allocation for the extracted finalizer block. |
| crates/oxc_minifier/src/peephole/minimize_statements.rs | Replaces manual block boxing with statement_block_with_scope_id helper for cleaner/faster block statement creation. |
| crates/oxc_minifier/src/peephole/minimize_if_statement.rs | Uses statement_block_with_scope_id to wrap a consequent in a scoped block without manual allocation/boxing. |
23c2d47 to
3e5ef15
Compare
25120f4 to
644b3d0
Compare
644b3d0 to
86b4184
Compare
3e5ef15 to
2e9ab4d
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.
2e9ab4d to
d025887
Compare
86b4184 to
3855f0c
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.