Skip to content

perf(parser): use ReplaceWith instead of TakeIn#24018

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/07-01-perf_parser_use_replacewith_instead_of_takein_
Jul 9, 2026
Merged

perf(parser): use ReplaceWith instead of TakeIn#24018
graphite-app[bot] merged 1 commit into
mainfrom
om/07-01-perf_parser_use_replacewith_instead_of_takein_

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jul 1, 2026

Copy link
Copy Markdown
Member

Replace one usage of take_in in parser with replace_with. See #24012 for explanation of the advantage of replace_with.

overlookmotel commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of 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.

@codspeed-hq

codspeed-hq Bot commented Jul 1, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 71.4%

⚡ 5 improved benchmarks
❌ 4 regressed benchmarks
✅ 53 untouched benchmarks
⏩ 9 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation react_compiler[binder.ts] 10.1 µs 2,612.2 µs -99.62%
Simulation react_compiler[react.development.js] 6.6 µs 1,024.5 µs -99.36%
Simulation react_compiler[kitchen-sink.tsx] 2.3 ms 19.3 ms -87.96%
Simulation react_compiler[App.tsx] 33.7 ms 44.6 ms -24.38%
Simulation react_compiler[RadixUIAdoptionSection.jsx] 8.3 ms 3.9 ms ×2.1
Simulation linter[RadixUIAdoptionSection.jsx] 9 ms 4.4 ms ×2
Simulation linter[binder.ts] 30.7 ms 27.1 ms +12.98%
Simulation linter[kitchen-sink.tsx] 180.3 ms 166.2 ms +8.5%
Simulation linter[react.development.js] 14.4 ms 13.5 ms +6.59%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing om/07-01-perf_parser_use_replacewith_instead_of_takein_ (018a8b8) with om/07-01-perf_minifier_use_replacewith_instead_of_takein_ (865115a)

Open in CodSpeed

Footnotes

  1. 9 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.

@overlookmotel
overlookmotel marked this pull request as ready for review July 1, 2026 16:38
Copilot AI review requested due to automatic review settings July 1, 2026 16:38

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.

Pull request overview

Updates the parser to use the newer ReplaceWith mutation pattern when rewriting AST nodes, avoiding the arena allocation of “dummy” nodes that take_in requires.

Changes:

  • Replaces a take_in-based rewrite of TSInstantiationExpression.expression with replace_with.
  • Updates imports in the parser expression module accordingly.

@overlookmotel
overlookmotel force-pushed the om/07-01-perf_minifier_use_replacewith_instead_of_takein_ branch from 4b6ee85 to c1fc2ce Compare July 1, 2026 18:01
@overlookmotel
overlookmotel force-pushed the om/07-01-perf_parser_use_replacewith_instead_of_takein_ branch from 4be451b to 04489c4 Compare July 1, 2026 18:01
@graphite-app
graphite-app Bot force-pushed the om/07-01-perf_minifier_use_replacewith_instead_of_takein_ branch from c1fc2ce to 5c8f03c Compare July 2, 2026 01:41
@graphite-app
graphite-app Bot requested a review from Dunqing as a code owner July 2, 2026 01:41
@graphite-app
graphite-app Bot force-pushed the om/07-01-perf_parser_use_replacewith_instead_of_takein_ branch from 04489c4 to d26fe7e Compare July 2, 2026 01:42
@overlookmotel
overlookmotel force-pushed the om/07-01-perf_minifier_use_replacewith_instead_of_takein_ branch from 5c8f03c to 865115a Compare July 2, 2026 21:50
@overlookmotel
overlookmotel force-pushed the om/07-01-perf_parser_use_replacewith_instead_of_takein_ branch from d26fe7e to 1226bef Compare July 2, 2026 21:50
@overlookmotel

overlookmotel commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Mode Benchmark BASE HEAD Efficiency
❌ Simulation react_compiler[binder.ts] 10.1 µs 2,610.9 µs -99.62%
❌ Simulation react_compiler[react.development.js] 6.6 µs 1,024.9 µs -99.36%
❌ Simulation react_compiler[kitchen-sink.tsx] 2.3 ms 19.3 ms -87.96%
❌ Simulation react_compiler[App.tsx] 33.7 ms 44.6 ms -24.42%
⚡ Simulation react_compiler[RadixUIAdoptionSection.jsx] 8.3 ms 3.9 ms ×2.1
⚡ Simulation linter[RadixUIAdoptionSection.jsx] 9 ms 4.4 ms ×2
⚡ Simulation linter[binder.ts] 30.7 ms 27.1 ms +13.08%
⚡ Simulation linter[kitchen-sink.tsx] 180.3 ms 166.1 ms +8.55%
⚡ Simulation linter[react.development.js] 14.4 ms 13.5 ms +6.85%

These benchmark results make no sense at all. Massive slowdown in React Compiler, 2x speed-up in linter, all from a tiny change to parser??? I'm pretty sure this is just Codspeed getting confused.

@overlookmotel
overlookmotel force-pushed the om/07-01-perf_parser_use_replacewith_instead_of_takein_ branch from 1226bef to 018a8b8 Compare July 3, 2026 00:33
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Jul 7, 2026

Dunqing commented Jul 7, 2026

Copy link
Copy Markdown
Member

Merge activity

  • Jul 7, 3:49 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Jul 8, 3:01 AM UTC: graphite-app added this pull request to the Graphite merge queue.
  • Jul 8, 3:05 AM UTC: The Graphite merge queue removed this pull request due to downstack failures on PR #24017.
  • Jul 8, 3:05 AM UTC: The Graphite merge queue removed this pull request due to downstack failures on PR #24017.
  • Jul 9, 2:46 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Jul 9, 2:46 AM UTC: This pull request can not be added to the Graphite merge queue. Please try rebasing and resubmitting to merge when ready.
  • Jul 9, 2:46 AM UTC: Graphite disabled "merge when ready" on this PR due to: a merge conflict with the target branch; resolve the conflict and try again..
  • Jul 9, 2:46 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Jul 9, 12:10 PM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Jul 9, 12:17 PM UTC: Merged by the Graphite merge queue.

@graphite-app
graphite-app Bot changed the base branch from om/07-01-perf_minifier_use_replacewith_instead_of_takein_ to graphite-base/24018 July 7, 2026 15:49
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jul 8, 2026
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Jul 9, 2026
@overlookmotel
overlookmotel force-pushed the om/07-01-perf_parser_use_replacewith_instead_of_takein_ branch from 018a8b8 to 8e608e8 Compare July 9, 2026 12:06
@overlookmotel
overlookmotel force-pushed the graphite-base/24018 branch from 865115a to 1ebdce3 Compare July 9, 2026 12:06
@overlookmotel
overlookmotel changed the base branch from graphite-base/24018 to main July 9, 2026 12:06
Replace one usage of `take_in` in parser with `replace_with`. See #24012 for explanation of the advantage of `replace_with`.
@graphite-app
graphite-app Bot force-pushed the om/07-01-perf_parser_use_replacewith_instead_of_takein_ branch from 8e608e8 to b47585c Compare July 9, 2026 12:11
@graphite-app
graphite-app Bot merged commit b47585c into main Jul 9, 2026
30 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jul 9, 2026
@graphite-app
graphite-app Bot deleted the om/07-01-perf_parser_use_replacewith_instead_of_takein_ branch July 9, 2026 12:17
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]>
graphite-app Bot pushed a commit to rolldown/rolldown that referenced this pull request Jul 15, 2026
…ue moves (#10285)

## What

Converts the `take_in` → build → write-back patterns in the module finalizer, scan pre-processor, HMR finalizer, and lazy-export generation to `oxc_allocator::ReplaceWith` (available since oxc 0.139) or plain by-value moves.

## Why

Each `take_in` writes a `Dummy` node into the vacated slot; for AST enums that dummy is a real arena allocation (16 bytes boxed) that is overwritten an instant later but stays in the pooled module arena until the generate stage ends. It advances the bump pointer (raising the pool's retained high-water mark) and lowers live-node density for every later walk over the same arena — scanner, DCE, finalizer, codegen. oxc's own parser (oxc-project/oxc#24018) and minifier (oxc-project/oxc#24017) made the same move in 0.140.0.

## How

- **Slot-level `replace_with`**: keep-name wraps (finalizer ×3), both dynamic-`import()`-in-CJS rewrites, the `.then((m) => __toESM(...))` interop wrapper, `replace_first_expr_stmt`, and the PreProcessor's `require(a?b:c)` / `import(a?b:c)` transposes (those destructure the conditional by value — 3 dummies each, now 0).
- **By-value with box reuse**: the finalizer's export-default block and the HMR finalizer's `handle_top_level_stmt` now match the owned statement directly, so `export default function/class` reuses the existing `Box<Function>`/`Box<Class>` instead of take-dummy-rebox (also saves the ~200-byte struct copy). `get_transformed_class_decl` takes the class box by value and returns `Result<Declaration, Box<Class>>`, giving the box back when no transform applies.
- **Plain moves where no trait is needed**: var-hoisting drains `declarations` by value (`Vec`'s dummy is an empty vec — no allocation), JSON prop inlining uses `Option::take`, and paren unwrapping in lazy export works by value.

Left as-is: the `Vec` drain-and-rebuild `take_in`s (free dummy, structurally required) and the `take_in_box` in the dynamic-import-to-other-chunk path, whose `Option`-returning protocol tolerates a partially consumed node on the warn paths.

One behavior note: the finalizer's export-default fallback arm is now `unreachable!()` for `TSInterfaceDeclaration` (TS is stripped before finalization), matching the convention already used by `visit_declaration` and the HMR finalizer for TS variants.

Output is byte-identical: the snapshot suite passes with zero snapshot updates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants