Skip to content

perf(generate): thread ast_table by value into codegen consumer#9555

Merged
IWANABETHATGUY merged 1 commit into
mainfrom
refactor/thread-ast-table-by-value-into-codegen
May 26, 2026
Merged

perf(generate): thread ast_table by value into codegen consumer#9555
IWANABETHATGUY merged 1 commit into
mainfrom
refactor/thread-ast-table-by-value-into-codegen

Conversation

@Boshen

@Boshen Boshen commented May 26, 2026

Copy link
Copy Markdown
Member

Summary

Alternative to #9554. Same memory win on the realistic case, enforced by the type system instead of by a comment.

Remove ast_table from LinkStageOutput and change LinkStage::link() to return (LinkStageOutput, IndexEcmaAst). The AST table then flows by value through bundle_up → GenerateStage::new → generate → finalize_modules → render_chunk_to_assets → instantiate_chunks → create_chunk_to_codegen_ret_map, where the compiler drops it at scope exit (create_chunk_to_codegen_ret_map is the last reader). Adding a new post-codegen ast_table reader becomes a compile error — there is no field to read.

Measured impact (3 runs each, verified locally with dhat + getrusage + /usr/bin/time -ahl)

Config main This PR Δ vs main Δ vs #9554
dhat At t-gmax (peak heap)
rome 140.51 MiB 108.07 MiB −32.4 MiB (−23.1 %) −2.08 MiB
rome --minify 159.78 MiB 113.09 MiB −46.7 MiB (−29.2 %) +0.01 MiB
ru_maxrss (getrusage, 3-run avg)
rome 172.05 MiB 170.56 MiB −1.49 MiB +1.17 MiB
rome --minify 183.56 MiB 175.71 MiB −7.85 MiB −5.70 MiB
time -ahl peak RSS (3-run avg)
rome 180.99 MiB 179.31 MiB −1.68 MiB +1.15 MiB
rome --minify 193.37 MiB 184.69 MiB −8.68 MiB −6.42 MiB

The ~2 MiB additional saving on rome no-minify vs #9554 comes from dropping one frame earlier (inside instantiate_chunks rather than after it returns) — which matters when peak heap is reached during instantiate_chunks's own try_join_all. On rome --minify, peak is firmly in finalize_assets, far past both drop points, so the two PRs are identical at the dhat level (the OS-RSS gap there is run-to-run noise — system malloc's page caching is sticky).

Trade-offs vs #9554

  • Pros: Compile-time guarantee that no post-codegen reader can exist.
  • Cons: 5 files instead of 1; signature changes through the codegen pipeline.

Pick one to land — they are mutually exclusive. The minimal version (#9554) is simpler; this one is what you'd reach for if the team values type-system enforcement over diff size.

Refs #9516.

@netlify

netlify Bot commented May 26, 2026

Copy link
Copy Markdown

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 800f077
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6a158b7d18685300084e6900

@codspeed-hq

codspeed-hq Bot commented May 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing refactor/thread-ast-table-by-value-into-codegen (6ce1d61) with main (df616cb)2

Open in CodSpeed

Footnotes

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

  2. No successful run was found on main (b291797) during the generation of this report, so df616cb was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Boshen added a commit that referenced this pull request May 26, 2026
…degen_ret_map

`ast_table: IndexEcmaAst` is consumed by value on purpose — the whole
point of #9555 is to have the compiler drop the per-module bumpalo
arenas at scope exit, before the rest of `instantiate_chunks` runs.
Clippy's `needless_pass_by_value` (pedantic) flags it because the body
only borrows; suppress with a comment explaining the intent.
@Boshen Boshen changed the title refactor(generate): thread ast_table by value into codegen consumer perf(generate): thread ast_table by value into codegen consumer May 26, 2026

Boshen commented May 26, 2026

Copy link
Copy Markdown
Member Author

Merge activity

  • May 26, 12:00 PM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • May 26, 12:00 PM UTC: Boshen added this pull request to the Graphite merge queue.
  • May 26, 12:31 PM UTC: This pull request was removed from the Graphite merge queue because the batch it was included in timed out. Please re-enqueue the PR to retry merge.

## Summary

Alternative to #9554. Same memory win on the realistic case, enforced by the type system instead of by a comment.

Remove `ast_table` from `LinkStageOutput` and change `LinkStage::link()` to return `(LinkStageOutput, IndexEcmaAst)`. The AST table then flows by value through `bundle_up → GenerateStage::new → generate → finalize_modules → render_chunk_to_assets → instantiate_chunks → create_chunk_to_codegen_ret_map`, where the compiler drops it at scope exit (`create_chunk_to_codegen_ret_map` is the last reader). Adding a new post-codegen `ast_table` reader becomes a compile error — there is no field to read.

## Measured impact (3 runs each, verified locally with dhat + getrusage + `/usr/bin/time -ahl`)

| Config | main | This PR | Δ vs main | Δ vs #9554 |
|---|---:|---:|---:|---:|
| **dhat At t-gmax (peak heap)** | | | | |
| rome | 140.51 MiB | 108.07 MiB | **−32.4 MiB (−23.1 %)** | −2.08 MiB |
| rome --minify | 159.78 MiB | 113.09 MiB | **−46.7 MiB (−29.2 %)** | +0.01 MiB |
| **ru_maxrss (getrusage, 3-run avg)** | | | | |
| rome | 172.05 MiB | 170.56 MiB | −1.49 MiB | +1.17 MiB |
| rome --minify | 183.56 MiB | 175.71 MiB | −7.85 MiB | −5.70 MiB |
| **time -ahl peak RSS (3-run avg)** | | | | |
| rome | 180.99 MiB | 179.31 MiB | −1.68 MiB | +1.15 MiB |
| rome --minify | 193.37 MiB | 184.69 MiB | −8.68 MiB | −6.42 MiB |

The ~2 MiB additional saving on rome no-minify vs #9554 comes from dropping one frame earlier (inside `instantiate_chunks` rather than after it returns) — which matters when peak heap is reached during `instantiate_chunks`'s own `try_join_all`. On rome --minify, peak is firmly in `finalize_assets`, far past both drop points, so the two PRs are identical at the dhat level (the OS-RSS gap there is run-to-run noise — system malloc's page caching is sticky).

## Trade-offs vs #9554

- Pros: Compile-time guarantee that no post-codegen reader can exist.
- Cons: 5 files instead of 1; signature changes through the codegen pipeline.

Pick one to land — they are mutually exclusive. The minimal version (#9554) is simpler; this one is what you'd reach for if the team values type-system enforcement over diff size.

Refs #9516.
@graphite-app graphite-app Bot force-pushed the refactor/thread-ast-table-by-value-into-codegen branch from 6ce1d61 to 800f077 Compare May 26, 2026 12:00
@IWANABETHATGUY IWANABETHATGUY disabled auto-merge May 26, 2026 14:59
@IWANABETHATGUY IWANABETHATGUY merged commit 258bc5d into main May 26, 2026
7 checks passed
@IWANABETHATGUY IWANABETHATGUY deleted the refactor/thread-ast-table-by-value-into-codegen branch May 26, 2026 15:00
@shulaoda shulaoda mentioned this pull request May 27, 2026
shulaoda added a commit that referenced this pull request May 27, 2026
## [1.0.3] - 2026-05-27

### 🚀 Features

- transform: respect decorator strictNullChecks option (#9580) by @kylecannon
- drop `defer` keyword (#9503) by @TheAlexLichter

### 🐛 Bug Fixes

- ci: create target dir before cargo release-oxc update (#9584) by @shulaoda
- ci: reorder prepare-release steps to avoid dirty git check failure (#9583) by @shulaoda
- testing: canonicalize temp dir early and use platform-specific separator in test262 (#9582) by @shulaoda
- testing: resolve symlinked temp dir in test262 snapshot normalization (#9581) by @shulaoda
- testing: canonicalize temp dir path in test262 snapshot normalization (#9579) by @shulaoda
- dev: `onOutput` called twice when initial build fails (#9552) by @hyf0
- dev: make `ensureCurrentBuildFinish` not returning error when engine closes (#9564) by @h-a-n-a
- oxc-runtime: route require() to CJS helper variant (#9263) (#9526) by @IWANABETHATGUY
- generator: use exporter chunk's export mode for CJS default re-exports (#9299) (#9529) by @IWANABETHATGUY
- rolldown: always run reduced-atom static cycle check (#9441) (#9514) by @IWANABETHATGUY
- apply transform.dropLabels before scanning (#9521) (#9522) by @IWANABETHATGUY
- rolldown_watcher: take `rolldown` dep through the workspace (#9510) by @Boshen
- cache: keep the scan-stage cache consistent when a build fails (#9495) by @h-a-n-a
- skip JSON default-import namespace optimization for write targets (#9484) (#9489) by @IWANABETHATGUY
- deps: skip pnpm frozen-lockfile on Netlify to dodge catalog mismatch bug (#9471) by @Boshen

### 🚜 Refactor

- oxc-runtime: use Cow for helper path construction (#9538) by @IWANABETHATGUY
- fold import defer phase drop into PreProcessor (#9524) by @IWANABETHATGUY
- distinguish `map: null` vs `map: undefined` in transform hook output (#9497) by @sapphi-red

### 📚 Documentation

- explain the policy for Rust crates (#9547) by @sapphi-red
- cache: add design doc for cache (#9544) by @h-a-n-a
- guide/troubleshooting: add TDZ error section (#9537) by @sapphi-red
- dev-engine: add design doc for dev-engine (#9479) by @h-a-n-a
- lazy-barrel: tweak some words (#9483) by @shulaoda
- lazy-barrel: expand reasoning behind LARGE_BARREL_MODULES advice (#9477) by @shulaoda

### ⚡ Performance

- generate: thread ast_table by value into codegen consumer (#9555) by @Boshen
- finalizers: replace `_reExport` construction with a direct call to avoid calling `clone_in` (#9501) by @Dunqing
- reorder hot-path boolean checks to short-circuit on cheap predicates first (#9523) by @Boshen

### 🧪 Testing

- rolldown: regression fixture for #9401 (#9418) by @IWANABETHATGUY
- failing test for #9441 (#9504) by @TheAlexLichter

### ⚙️ Miscellaneous Tasks

- deps: upgrade oxc to 0.133.0 (#9563) by @Dunqing
- deps: update crate-ci/typos action to v1.46.3 (#9576) by @renovate[bot]
- deps: update mimalloc-safe to 0.1.62 (#9577) by @shulaoda
- mimalloc-safe: update to a bug-fix branch for verification (#9569) by @shulaoda
- deps: update test262 submodule for tests (#9551) by @rolldown-guard[bot]
- point published crates' readme to root README.md (#9553) by @Boshen
- replace actions-cool/issues-helper with gh CLI (#9543) by @Boshen
- deps: update cargo-shear to 1.12.4 (#9541) by @Boshen
- deps: update taiki-e/install-action action to v2.79.4 (#9535) by @renovate[bot]
- deps: update github actions (#9532) by @renovate[bot]
- deps: update rust crates (#9534) by @renovate[bot]
- deps: update npm packages (#9533) by @renovate[bot]
- gate experimental/testing-only items to silence dead_code in publish builds (#9517) by @Boshen
- docs: deploy to Void (#9509) by @Boshen
- release: set up cargo-release-oxc for publishing crates (#9476) by @Boshen
- rolldown_plugin_lazy_compilation: add missing description (#9507) by @Boshen
- mimalloc-safe: update to a bug-fix branch for verification (#9506) by @shulaoda
- deps: update crate-ci/typos action to v1.46.2 (#9468) by @renovate[bot]

### ❤️ New Contributors

* @kylecannon made their first contribution in [#9580](#9580)
shulaoda pushed a commit that referenced this pull request May 27, 2026
## [1.0.3] - 2026-05-27

### 🚀 Features

- transform: respect decorator strictNullChecks option (#9580) by @kylecannon
- drop `defer` keyword (#9503) by @TheAlexLichter

### 🐛 Bug Fixes

- ci: create target dir before cargo release-oxc update (#9584) by @shulaoda
- ci: reorder prepare-release steps to avoid dirty git check failure (#9583) by @shulaoda
- testing: canonicalize temp dir early and use platform-specific separator in test262 (#9582) by @shulaoda
- testing: resolve symlinked temp dir in test262 snapshot normalization (#9581) by @shulaoda
- testing: canonicalize temp dir path in test262 snapshot normalization (#9579) by @shulaoda
- dev: `onOutput` called twice when initial build fails (#9552) by @hyf0
- dev: make `ensureCurrentBuildFinish` not returning error when engine closes (#9564) by @h-a-n-a
- oxc-runtime: route require() to CJS helper variant (#9263) (#9526) by @IWANABETHATGUY
- generator: use exporter chunk's export mode for CJS default re-exports (#9299) (#9529) by @IWANABETHATGUY
- rolldown: always run reduced-atom static cycle check (#9441) (#9514) by @IWANABETHATGUY
- apply transform.dropLabels before scanning (#9521) (#9522) by @IWANABETHATGUY
- rolldown_watcher: take `rolldown` dep through the workspace (#9510) by @Boshen
- cache: keep the scan-stage cache consistent when a build fails (#9495) by @h-a-n-a
- skip JSON default-import namespace optimization for write targets (#9484) (#9489) by @IWANABETHATGUY
- deps: skip pnpm frozen-lockfile on Netlify to dodge catalog mismatch bug (#9471) by @Boshen

### 🚜 Refactor

- oxc-runtime: use Cow for helper path construction (#9538) by @IWANABETHATGUY
- fold import defer phase drop into PreProcessor (#9524) by @IWANABETHATGUY
- distinguish `map: null` vs `map: undefined` in transform hook output (#9497) by @sapphi-red

### 📚 Documentation

- explain the policy for Rust crates (#9547) by @sapphi-red
- cache: add design doc for cache (#9544) by @h-a-n-a
- guide/troubleshooting: add TDZ error section (#9537) by @sapphi-red
- dev-engine: add design doc for dev-engine (#9479) by @h-a-n-a
- lazy-barrel: tweak some words (#9483) by @shulaoda
- lazy-barrel: expand reasoning behind LARGE_BARREL_MODULES advice (#9477) by @shulaoda

### ⚡ Performance

- generate: thread ast_table by value into codegen consumer (#9555) by @Boshen
- finalizers: replace `_reExport` construction with a direct call to avoid calling `clone_in` (#9501) by @Dunqing
- reorder hot-path boolean checks to short-circuit on cheap predicates first (#9523) by @Boshen

### 🧪 Testing

- rolldown: regression fixture for #9401 (#9418) by @IWANABETHATGUY
- failing test for #9441 (#9504) by @TheAlexLichter

### ⚙️ Miscellaneous Tasks

- deps: upgrade oxc to 0.133.0 (#9563) by @Dunqing
- deps: update crate-ci/typos action to v1.46.3 (#9576) by @renovate[bot]
- deps: update mimalloc-safe to 0.1.62 (#9577) by @shulaoda
- mimalloc-safe: update to a bug-fix branch for verification (#9569) by @shulaoda
- deps: update test262 submodule for tests (#9551) by @rolldown-guard[bot]
- point published crates' readme to root README.md (#9553) by @Boshen
- replace actions-cool/issues-helper with gh CLI (#9543) by @Boshen
- deps: update cargo-shear to 1.12.4 (#9541) by @Boshen
- deps: update taiki-e/install-action action to v2.79.4 (#9535) by @renovate[bot]
- deps: update github actions (#9532) by @renovate[bot]
- deps: update rust crates (#9534) by @renovate[bot]
- deps: update npm packages (#9533) by @renovate[bot]
- gate experimental/testing-only items to silence dead_code in publish builds (#9517) by @Boshen
- docs: deploy to Void (#9509) by @Boshen
- release: set up cargo-release-oxc for publishing crates (#9476) by @Boshen
- rolldown_plugin_lazy_compilation: add missing description (#9507) by @Boshen
- mimalloc-safe: update to a bug-fix branch for verification (#9506) by @shulaoda
- deps: update crate-ci/typos action to v1.46.2 (#9468) by @renovate[bot]

### ❤️ New Contributors

* @kylecannon made their first contribution in [#9580](#9580)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants