perf(ast): add #[inline(always)] to node_id methods on enums with all variants unboxed#21707
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR updates the AST get_id code generator to mark node_id accessors on enum wrappers as #[inline(always)] when all variants have a consistent representation (all boxed or all unboxed), improving the optimizer’s ability to reduce these accessors to minimal code.
Changes:
- Extend
get_idgenerator logic to detect “all variants unboxed” in addition to “all variants boxed”. - Emit
#[inline(always)]on generatednode_idmethods when variants are consistently boxed or consistently unboxed. - Regenerate
crates/oxc_ast/src/generated/get_id.rsto include the new attributes for qualifying enums.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tasks/ast_tools/src/generators/get_id.rs | Adjusts generation logic to add #[inline(always)] for consistently boxed or consistently unboxed enum variants. |
| crates/oxc_ast/src/generated/get_id.rs | Updates generated node_id methods to include the new inline attributes where applicable. |
6223be0 to
3ec862c
Compare
9975e2f to
3162b88
Compare
3ec862c to
170efe9
Compare
3162b88 to
7fd757b
Compare
Merge activity
|
… all variants unboxed (#21707) Follow-on after #21653. That PR revealed that some AST enums don't have all their variants boxed. Where all variants are boxed, `node_id` methods should boil down to a single instruction, so we mark the method `#[inline(always)]`. `node_id` method will also boil down to a single instruction where all variants are _not_ boxed, so add `#[inline(always)]` to them too. It's only where there's a mix of boxed and unboxed where the method will retain branching logic and be larger. Probably compiler will inline these methods anyway, but the attributes are a useful signal as to where we can improve the AST - all enums should consistently box _all_ their variants, or none of them.
7fd757b to
5c93af8
Compare
170efe9 to
cab32ae
Compare
### 💥 BREAKING CHANGES - 502e804 ast: [**BREAKING**] Reduce size of `TSTypePredicateName` (#21711) (overlookmotel) - 5651539 ast: [**BREAKING**] Reduce size of `JSXExpression` (#21710) (overlookmotel) - c44e280 ast: [**BREAKING**] Reduce size of `ArrayExpressionElement` (#21709) (overlookmotel) - c5b3deb syntax: [**BREAKING**] Remove `CommentNodeId` (#21679) (overlookmotel) ### 🚀 Features - b738a39 allocator: Add `Allocator::cursor_ptr` method (#21773) (overlookmotel) - 678767e ast: Generate node_id accessors for AST enum wrappers (#21653) (camc314) - f091d77 minifier: Inline constant spread elements into arrays (#21095) (Armano) ### 🐛 Bug Fixes - 0d608c2 minifier: Preserve raw CR in template literals (#21645) (Dunqing) - a889ea9 minifier: Track pure functions in DCE mode (#21722) (Dunqing) - 674dfac allocator: `Arena` retry allocation when chunk size approaches maximum (#21777) (overlookmotel) - f130cc0 allocator: Fix arithmetic overflow in `Arena::new_chunk_memory_details` (#21745) (overlookmotel) - b9bf239 allocator: Fix UB in `Arena::grow_zeroed` (#21739) (overlookmotel) - d2b9389 allocator: Clippy warning when building without `testing` feature (#21681) (camc314) - 503dc86 codegen: Map sourcemaps from visible output starts (#21662) (Dunqing) - c92bd3b transformer: Use SPAN for synthesized helper calls to prevent comment misattribution (#21578) (Dunqing) - 0d80441 codegen: Add mapping before printing `#` for private ident (#21619) (camc314) ### ⚡ Performance - 9fa362e napi/parser: Do not generate tokens except in tests (#21811) (overlookmotel) - 0044392 allocator: Reduce branches when allocating new chunk (#21776) (overlookmotel) - 7896bd0 allocator: `Allocator::used_bytes` do not use chunk iterator (#21771) (overlookmotel) - a5c562f allocator: Remove check in `Arena::new_chunk_memory_details` (#21750) (overlookmotel) - 35bbe1f allocator: `Arena` use unchecked size round up where guaranteed no overflow (#21743) (overlookmotel) - ffe229b allocator: Remove unnecessary check from `Arena::try_alloc_layout_slow_impl` (#21732) (overlookmotel) - 72fece5 allocator: Use `NonNull::offset_from_unsigned` in `Arena::chunk_capacity` (#21731) (overlookmotel) - cab32ae ast: Add `#[inline(always)]` to `node_id` methods on enums with all variants unboxed (#21707) (overlookmotel) - b179688 parser: Allocate `TriviaBuilder` comments in the arena (#21512) (Boshen) - 2290f31 lexer: Fix perf of `Token::set_*` methods on Rust 1.95.0 (#21659) (overlookmotel) - 1b58029 allocator: Move code into cold path in `Arena::alloc_layout` (#21622) (overlookmotel) - 3cf7cef allocator: Reduce instructions on allocation hot path (#21510) (overlookmotel) ### 📚 Documentation - ce65070 data_structures: Document why `as_ref` and `as_mut` on `NonNullConst` and `NonNullMut` take `self` (#21800) (overlookmotel) - 93b7dbd allocator: Improve doc comments for `ChunkFooter` (#21733) (overlookmotel) - 295db8d transformer: Fix comment (#21717) (overlookmotel) - 5c93af8 ast: Add comments explaining `#[inline(always)]` to `node_id` methods on enums (#21706) (overlookmotel) - e4cea25 transform: Use the `node:` namespace in the example (#19998) (루밀LuMir) ### 🛡️ Security - d8076c9 deps: Update rolldown (#21639) (renovate) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

Follow-on after #21653.
That PR revealed that some AST enums don't have all their variants boxed. Where all variants are boxed,
node_idmethods should boil down to a single instruction, so we mark the method#[inline(always)].node_idmethod will also boil down to a single instruction where all variants are not boxed, so add#[inline(always)]to them too. It's only where there's a mix of boxed and unboxed where the method will retain branching logic and be larger.Probably compiler will inline these methods anyway, but the attributes are a useful signal as to where we can improve the AST - all enums should consistently box all their variants, or none of them.