perf: reuse scoping rebuilds in preprocessing via Scoping::reset#9460
perf: reuse scoping rebuilds in preprocessing via Scoping::reset#9460Dunqing wants to merge 3 commits into
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
Merging this PR will not alter performance
Comparing Footnotes
|
8e893e7 to
01f3a77
Compare
Pulls in oxc-project/oxc@2b6ee676 which pre-reserves unresolved_references based on Stats::references, eliminating ~13 growth reallocations per SemanticBuilder::build. Triggers CodSpeed re-run.
|
Closing this PR. WhyThis PR threaded a After investigation, the rolldown-side changes here don't actually deliver measurable performance improvements:
The right pathWait for oxc #22580 to merge. When the next oxc release ships, rolldown's If a future iteration of rolldown's preprocessing pipeline benefits from new oxc APIs (e.g., a Honest acknowledgmentI shipped this PR with bench numbers I hadn't sanity-checked against a controlled experiment. The numbers turned out to be noise. Closing this is the right call — the API surface and code complexity added by threading |
Summary
Threads a
recycled_scoping: Option<Scoping>throughPreProcessEcmaAst::buildso the staleScopingafter each AST-mutating pass (transformer / define / inject / DCE) can be recycled. The nextrecreate_scopingcall usesScoping::resetto clear it in place — preserving the bumpalo arena's chunks and the flat-table heap capacity — and feeds it back toSemanticBuilder::with_scoping. This avoids the allocator init cost on each rebuild (3-4 times per file).DCE is switched from
dead_code_elimination_with_scoping(consumes the scoping) todead_code_elimination_with_scoping_returning_scopingso the post-DCE scoping can be recycled too.The initial Step 1 build (
with_check_syntax_error(true)) is unchanged — the syntax checker still uses the default builder.Benchmark
cargo bench -p bench, this branch vsorigin/main:Three out of four show clear wins.
Depends on
Upstream oxc PR adding the APIs: oxc-project/oxc#22571. The
[patch.crates-io]section in this PR points at that branch; remove the patch once oxc 0.133.0 (or whichever version the APIs land in) is published.Test Plan
cargo test -p rolldown --lib— 56 tests passAI disclosure: drafted with Claude Code, reviewed manually.