Skip to content

perf(transformer): fix Rust 1.97 performance regression#24354

Merged
graphite-app[bot] merged 1 commit into
mainfrom
c/fix-transformer-perf-regression
Jul 10, 2026
Merged

perf(transformer): fix Rust 1.97 performance regression#24354
graphite-app[bot] merged 1 commit into
mainfrom
c/fix-transformer-perf-regression

Conversation

@camc314

@camc314 camc314 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What regressed?

The Rust 1.97 upgrade changed LLVM’s inlining decisions around the ES2022 transformer expression visitor.

The hot benchmark path is:

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:

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:

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:

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:

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:

; 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:

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:

#[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:

#[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:

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:

; 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.

Copilot AI review requested due to automatic review settings July 10, 2026 09:42
@camc314
camc314 requested a review from Dunqing as a code owner July 10, 2026 09:42

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the A-transformer Area - Transformer / Transpiler label Jul 10, 2026
@camc314 camc314 changed the title perf: fix perf(transformer): fix Rust 1.97 performance regression Jul 10, 2026
@camc314
camc314 marked this pull request as draft July 10, 2026 09:45
@codspeed-hq

codspeed-hq Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 3.95%

⚡ 4 improved benchmarks
✅ 48 untouched benchmarks
⏩ 19 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation transformer[react.development.js] 756.5 µs 723 µs +4.63%
Simulation transformer[binder.ts] 1.9 ms 1.8 ms +4.54%
Simulation transformer[App.tsx] 7.6 ms 7.4 ms +3.59%
Simulation transformer[kitchen-sink.tsx] 17 ms 16.5 ms +3.04%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing c/fix-transformer-perf-regression (7aa873d) with main (8337835)

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.

@camc314
camc314 force-pushed the c/fix-transformer-perf-regression branch from 869fff8 to 7aa873d Compare July 10, 2026 09:49
@camc314
camc314 marked this pull request as ready for review July 10, 2026 10:05
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Jul 10, 2026
@camc314 camc314 self-assigned this Jul 10, 2026

camc314 commented Jul 10, 2026

Copy link
Copy Markdown
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
graphite-app Bot force-pushed the c/fix-transformer-perf-regression branch from 7aa873d to ab22e80 Compare July 10, 2026 10:06
@graphite-app
graphite-app Bot merged commit ab22e80 into main Jul 10, 2026
29 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jul 10, 2026
@graphite-app
graphite-app Bot deleted the c/fix-transformer-perf-regression branch July 10, 2026 10:12
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]>
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.

2 participants