perf(transformer): fix Rust 1.97 performance regression#24354
Merged
Conversation
camc314
marked this pull request as draft
July 10, 2026 09:45
Merging this PR will improve performance by 3.95%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
camc314
force-pushed
the
c/fix-transformer-perf-regression
branch
from
July 10, 2026 09:49
869fff8 to
7aa873d
Compare
camc314
marked this pull request as ready for review
July 10, 2026 10:05
Contributor
Author
Merge activity
|
## What regressed?
The Rust 1.97 upgrade changed LLVM’s inlining decisions around the ES2022 transformer expression visitor.
The hot benchmark path is:
```text
oxc_traverse::generated::walk::walk_expression
-> TransformerImpl::enter_expression
-> ES2022::enter_expression
-> ClassProperties::enter_expression
```
`ClassProperties::enter_expression` is meant to be cheap for most expressions. It first checks whether we are currently inside a class with private fields:
```rust
if self.private_field_count == 0 {
return;
}
```
For most benchmark files, this is the common path. If there are no active private fields, none of the private-field expression transforms can apply.
With Rust 1.96, LLVM kept the large private-field transform implementations out of the hot visitor, so `ES2022::enter_expression` was still small enough to inline into the generated walker:
```text
Rust 1.96:
<ES2022 as Traverse>::enter_expression
inlined into oxc_traverse::generated::walk::walk_expression
cost=-11965, threshold=250
```
With Rust 1.97, LLVM started inlining several large private-field transform bodies into `ES2022::enter_expression` first:
```text
Rust 1.97:
transform_assignment_expression_impl
inlined into ES2022::enter_expression
cost=-8825, threshold=250
transform_update_expression_impl
inlined into ES2022::enter_expression
cost=-5390, threshold=250
transform_tagged_template_expression_impl
inlined into ES2022::enter_expression
cost=-14555, threshold=250
```
After those large branches were pulled in, `ES2022::enter_expression` became too large to inline into the generated walker:
```text
Rust 1.97:
<ES2022 as Traverse>::enter_expression
not inlined into oxc_traverse::generated::walk::walk_expression
cost=4265, threshold=250
```
So the regression is not a semantic change. It is a codegen shape change: the generated walker lost a very cheap inlined fast path and started paying an extra call / worse layout on every expression visit.
## Assembly shape
In the Rust 1.96 build, `walk_expression` had the ES2022/ClassProperties fast path inlined. The walker checks whether the class-properties transform is active and whether private fields are currently in scope, then only branches into private-field handling when needed.
A representative part of the Rust 1.96 walker looked like this:
```asm
; ClassProperties state exists?
ldr x8, [x20, #0x478]
cbz x8, <skip_private_field_transform>
; Load expression discriminant
ldr x8, [sp, #0x88]
ldrb w8, [x8]
; Dispatch only to relevant expression cases
cmp w8, #0xc
b.eq <assignment_expression_case>
...
cmp w8, #0x1d
b.ne <skip_private_field_transform>
; Only call the heavy helper after matching the expression kind
bl transform_update_expression_impl
b <skip_private_field_transform>
```
For example, the clean Rust 1.96 walker still had direct calls to the rare helpers, but only behind expression-kind checks:
```asm
bl transform_call_expression_impl
bl transform_update_expression_impl
bl transform_tagged_template_expression_impl
bl transform_private_field_expression_impl
bl transform_assignment_expression_impl
bl transform_unary_expression_impl
bl transform_chain_expression_impl
```
In the bad Rust 1.97 shape, the outer ES2022 visitor was no longer inlined into `walk_expression`, because LLVM had already inflated it by inlining the large private-field branches. That left the hot walker path with a call to the ES2022 expression visitor instead of the cheap inlined guard.
## Fix
This PR makes the intended hot/cold split explicit:
```rust
#[inline]
fn enter_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
if let Some(class_properties) = &mut self.class_properties {
class_properties.enter_expression(expr, ctx);
}
}
```
and:
```rust
#[inline]
fn enter_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
if self.private_field_count != 0 {
self.enter_expression_with_private_fields(expr, ctx);
}
}
#[inline(never)]
fn enter_expression_with_private_fields(...) {
match expr {
Expression::PrivateFieldExpression(_) => ...
Expression::CallExpression(_) => ...
Expression::AssignmentExpression(_) => ...
...
}
}
```
The important bit is that the common case remains tiny:
```text
if private_field_count != 0 {
slow_private_field_dispatch(...)
}
```
The large private-field expression dispatch is still available, but it no longer pollutes the hot expression visitor and no longer prevents the ES2022 hook from being inlined into the generated walker.
The patched walker now has the intended shape:
```asm
; Check class-properties/private-field state
ldr x8, [x20, #0x478]
cbz x8, <skip_private_field_transform>
; Only call out when private fields are active
add x0, x20, #0x3f8
ldr x1, [sp, #0x90]
mov x2, x28
bl ClassProperties::enter_expression_with_private_fields
<skip_private_field_transform>:
```
This keeps the common no-private-fields path small while preventing Rust 1.97 from re-inlining the large rare private-field transform bodies into the generated walker.
graphite-app
Bot
force-pushed
the
c/fix-transformer-perf-regression
branch
from
July 10, 2026 10:06
7aa873d to
ab22e80
Compare
Boshen
added a commit
that referenced
this pull request
Jul 14, 2026
### 🚀 Features - 616bfa2 minifier: Remove unreachable code after terminating statements (#24441) (Dunqing) - ddab89a data_structures: Add `likely` and `unlikely` functions (#24368) (overlookmotel) - a3a39f9 react_compiler: Implement enableEmitHookGuards codegen (#24329) (Boshen) - b79eef7 minifier: Apply De Morgan's law to negated comparison chains in jump guards and loop tests (#24279) (Dunqing) - 34ff7b4 minifier: Drop write-only property assignments to unused local bindings by default (#24112) (Dunqing) - 1b829d8 semantic: Record const enums in EnumData (#24268) (Dunqing) - ba0944c semantic: Add `Scoping::set_symbol_span` (#24221) (camc314) ### 🐛 Bug Fixes - 7d33363 minifier: Preserve guaranteed throws from class heritage evaluation (#24349) (Dunqing) - 058a62f semantic: Track ambient contexts in `SemanticBuilder` (#24327) (camc314) - 721eb0b transformer/decorator: Scope accessor class binding (#24330) (camc314) - 1ebdce3 semantic: Allow reserved keywords in ambient declaration types (#24325) (camc314) - 460176a track-memory-allocations: Exclude arena chunks from Sys allocs (#24292) (Dunqing) - af4922b transformer: Clear lowered namespace redeclarations (#24300) (camc314) - ffd2765 semantic: Mark declared computed `MethodDefinition`s as type references (#24296) (camc314) - f17514b isolated-declarations: Emit const readonly fields as types (#24288) (camc314) - 40f769d minifier: Make `__proto__` write tracking execution-order independent (#24280) (Dunqing) - 6371fed transformer: Remove stale enum member bindings (#24272) (camc314) - f05dfab transformer: Correct symbol flags for lowered namespaces (#24271) (Dunqing) - 84eeb55 transformer: Correct symbol flags for lowered enums (#24269) (Dunqing) - c3057da transformer: Preserve generated class binding spans (#24220) (camc314) - 8260096 transformer: Correct span for lowered namespace symbol (#24222) (camc314) - 42d00d3 semantic: Mark declared class heritage as type references (#24237) (camc314) - 588d997 semantic: Mark TS `PropertyDefinition`s computed fields as type references (#24233) (camc314) - 9b95632 semantic: Mark computed method keys in `TSMethodSignature`s as type references (#24232) (camc314) ### ⚡ Performance - 5b26643 transformer_plugins: Dispatch global defines by trailing name (#23666) (Boshen) - dce0f29 react_compiler: Replace all compiled functions in a single AST walk (#24403) (Boshen) - f85f0d8 ast: Delegate inherited enum variants in clone_in and estree derives (#23555) (Boshen) - 3ff0234 allocator: Remove `unwrap` from `ReplaceWith` (#24365) (overlookmotel) - ab22e80 transformer: Fix Rust 1.97 performance regression (#24354) (camc314) - b47585c parser: Use `ReplaceWith` instead of `TakeIn` (#24018) (overlookmotel) - b227a06 minifier: Use `ReplaceWith` instead of `TakeIn` (#24017) (overlookmotel) Co-authored-by: Boshen <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What regressed?
The Rust 1.97 upgrade changed LLVM’s inlining decisions around the ES2022 transformer expression visitor.
The hot benchmark path is:
ClassProperties::enter_expressionis meant to be cheap for most expressions. It first checks whether we are currently inside a class with private fields:For most benchmark files, this is the common path. If there are no active private fields, none of the private-field expression transforms can apply.
With Rust 1.96, LLVM kept the large private-field transform implementations out of the hot visitor, so
ES2022::enter_expressionwas still small enough to inline into the generated walker:With Rust 1.97, LLVM started inlining several large private-field transform bodies into
ES2022::enter_expressionfirst:After those large branches were pulled in,
ES2022::enter_expressionbecame too large to inline into the generated walker:So the regression is not a semantic change. It is a codegen shape change: the generated walker lost a very cheap inlined fast path and started paying an extra call / worse layout on every expression visit.
Assembly shape
In the Rust 1.96 build,
walk_expressionhad the ES2022/ClassProperties fast path inlined. The walker checks whether the class-properties transform is active and whether private fields are currently in scope, then only branches into private-field handling when needed.A representative part of the Rust 1.96 walker looked like this:
For example, the clean Rust 1.96 walker still had direct calls to the rare helpers, but only behind expression-kind checks:
In the bad Rust 1.97 shape, the outer ES2022 visitor was no longer inlined into
walk_expression, because LLVM had already inflated it by inlining the large private-field branches. That left the hot walker path with a call to the ES2022 expression visitor instead of the cheap inlined guard.Fix
This PR makes the intended hot/cold split explicit:
and:
The important bit is that the common case remains tiny:
The large private-field expression dispatch is still available, but it no longer pollutes the hot expression visitor and no longer prevents the ES2022 hook from being inlined into the generated walker.
The patched walker now has the intended shape:
This keeps the common no-private-fields path small while preventing Rust 1.97 from re-inlining the large rare private-field transform bodies into the generated walker.