Skip to content

perf(es/minifier): reduce usage analysis overhead#11863

Draft
hardfist wants to merge 23 commits into
swc-project:mainfrom
hardfist:perf/micro-optimize-ecma-minifier
Draft

perf(es/minifier): reduce usage analysis overhead#11863
hardfist wants to merge 23 commits into
swc-project:mainfrom
hardfist:perf/micro-optimize-ecma-minifier

Conversation

@hardfist
Copy link
Copy Markdown
Collaborator

@hardfist hardfist commented May 17, 2026

Description:

Micro-optimization work for the ECMAScript minifier. Current patch reduces usage-analysis, DCE, renamer, and optimizer inline-map overhead on large modules while preserving existing behavior.

Micro-Optimization Progress

Target benchmark: swc_ecma_minifier single-file TypeScript minifier run (benches/full/typescript.js)
Measurement mode: valgrind --tool=callgrind
Primary metric: Ir
Baseline command: RUST_LOG=off valgrind --tool=callgrind --callgrind-out-file=... target/release/examples/minifier benches/full/typescript.js

Commit Benchmark Mode Ir Before Ir After Ir Delta Checks Notes
ceea09e1f8 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,523,555,239 -0.62% cargo fmt --all; cargo test -p swc_ecma_transforms_optimization; cargo test -p swc_ecma_minifier Initial progress toward 5%.
38f4f3e7d9 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,498,673,241 -1.07% cargo fmt --all; cargo test -p swc_ecma_utils; cargo test -p swc_ecma_transforms_optimization; cargo test -p swc_ecma_minifier; crates/swc_ecma_minifier/./scripts/exec.sh; cargo clippy --all --all-targets -- -D warnings Further progress; target not complete yet.
fb3c8be211 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,490,035,410 -1.23% cargo fmt --all; cargo test -p swc_ecma_minifier; crates/swc_ecma_minifier/./scripts/exec.sh; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Specializes finalizer literal-only traversal; target not complete yet.
ec08f30f6d examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,485,854,488 -1.30% cargo test -p swc_ecma_transforms_optimization; cargo clippy -p swc_ecma_transforms_optimization --all-targets -- -D warnings Caches DCE parent scope path state; target not complete yet.
93d0cbb514 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,485,136,348 -1.32% cargo test -p swc_ecma_transforms_optimization; cargo clippy -p swc_ecma_transforms_optimization --all-targets -- -D warnings Skips empty top_retain scans in DCE drop checks; target not complete yet.
1ec437a93e examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,482,169,581 -1.37% cargo test -p swc_ecma_utils; cargo clippy -p swc_ecma_utils --all-targets -- -D warnings Checks Math.* side-effect context before atom text; target not complete yet.
fc70244aa0 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,480,340,032 -1.40% cargo test -p swc_ecma_utils; cargo clippy -p swc_ecma_utils --all-targets -- -D warnings Applies the same context-first guard for pure member callees; target not complete yet.
3ffd55bf2a examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,480,276,424 -1.40% cargo test -p swc_ecma_utils; cargo clippy -p swc_ecma_utils --all-targets -- -D warnings Checks identifier contexts before pure number/string casts; target not complete yet.
2b9b9859e3 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,477,865,257 -1.45% cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Skips delete handling for non-unary expressions; target not complete yet.
1558303f6c examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,463,148,238 -1.71% cargo fmt --all; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Checks identifier context before usage-map lookup; target not complete yet.
44316f60d5 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,462,573,553 -1.72% cargo fmt --all; cargo test -p swc_ecma_transforms_base; cargo clippy -p swc_ecma_transforms_base --all-targets -- -D warnings Uses release extend while accumulating renamer cache updates; target not complete yet.
44b08d8e9f examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,453,904,419 -1.88% cargo fmt --all; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Reserves top-level usage-analysis storage for large modules; target not complete yet.
d26e2a8c85 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,429,174,793 -2.32% cargo fmt --all; cargo test -p swc_ecma_transforms_optimization; cargo clippy -p swc_ecma_transforms_optimization --all-targets -- -D warnings Reserves DCE analyzer storage for large modules; target not complete yet.
8ba9e3b920 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,417,383,207 -2.53% cargo fmt --all; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Reserves optimizer inline maps based on analyzed binding count; target not complete yet.
8056c14022 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,390,205,201 -3.02% cargo fmt --all; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Stores VarUsageInfo inline in ProgramData.vars to avoid per-binding boxes; target not complete yet.
a750dc8391 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,390,134,723 -3.02% cargo fmt --all; cargo check -p swc_ecma_minifier; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Skips recursive-usage hash lookup when no recursive ids are active; target not complete yet.
7e3d5651fc examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,388,848,817 -3.05% cargo fmt --all; cargo check -p swc_ecma_minifier; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Compares pure-pass identifiers directly and avoids redundant member downcasts; target not complete yet.
1654ab203e examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,348,517,169 -3.77% cargo fmt --all; cargo check -p swc_ecma_minifier; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Uses a single occupied-entry lookup when consuming inline variables; target not complete yet.
ff6efc15a6 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,348,385,188 -3.78% cargo fmt --all; cargo check -p swc_ecma_minifier; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Retunes inline-map reserves after the occupied-entry lookup change; target not complete yet.
0d68d6321c examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,332,892,051 -4.06% cargo fmt --all; cargo check -p swc_ecma_transforms_base; cargo test -p swc_ecma_transforms_base; cargo clippy -p swc_ecma_transforms_base --all-targets -- -D warnings; cargo check -p swc_ecma_minifier; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Uses string comparison for renamer arguments filters and reserves scope identifier storage before merging child scopes; target not complete yet.
d93b793664 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,304,610,408 -4.56% cargo fmt --all; cargo check -p swc_ecma_minifier; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Defers initialized_vars lookups while merging usage data until the branch needs them; target not complete yet.
7e1a9d5ae2 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,302,436,151 -4.60% cargo fmt --all; cargo test -p swc_ecma_transforms_optimization; cargo clippy -p swc_ecma_transforms_optimization --all-targets -- -D warnings; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings Reuses computed identifiers in usage tracking and reserves accessed-property storage on first use; target not complete yet.
e2d6f95538 examples/minifier benches/full/typescript.js Callgrind Ir 5,558,264,214 5,263,249,353 -5.31% cargo fmt --all; cargo test -p swc_ecma_transforms_optimization; cargo test -p swc_ecma_minifier; cargo clippy -p swc_ecma_transforms_optimization --all-targets -- -D warnings; cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings; cargo clippy --all --all-targets -- -D warnings Replaces DCE graph index storage with a direct map plus reverse ids, skips no-op usage-data merges, and avoids property-atom root lookups when collection is disabled. Target reached.

Local artifacts are under optimization-artifacts/callgrind/ and are intentionally not committed.

BREAKING CHANGE:

None.

Related issue (if exists):

N/A

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 17, 2026

⚠️ No Changeset found

Latest commit: e2d6f95

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 17, 2026

Merging this PR will not alter performance

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 10 improved benchmarks
❌ 4 regressed benchmarks
✅ 205 untouched benchmarks
⏩ 31 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
es/large/minify/libraries/d3 494.5 ms 483.1 ms +2.36%
es/large/minify/libraries/lodash 142.2 ms 138.4 ms +2.76%
es/large/minify/libraries/react 24.3 ms 24.9 ms -2.44%
es/large/minify/libraries/typescript 4.6 s 4.5 s +2.82%
es/minifier/libs/d3 377.5 ms 363.9 ms +3.72%
es/minifier/libs/echarts 1.4 s 1.4 s +2.13%
es/minifier/libs/three 598.2 ms 584 ms +2.43%
es/minifier/libs/jquery 89.8 ms 87.6 ms +2.5%
es/minifier/libs/typescript 3.5 s 3.4 s +3.95%
es/minifier/libs/lodash 108.4 ms 104.4 ms +3.79%
es/minifier/libs/vue 135.5 ms 132.5 ms +2.25%
es/minifier/libs/react 18.5 ms 19.2 ms -3.29%
stackoverflow 38.3 ms 45.1 ms -15.1%
stackoverflow 37.5 ms 43.6 ms -14.09%

Tip

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


Comparing hardfist:perf/micro-optimize-ecma-minifier (e2d6f95) with main (800bc17)2

Open in CodSpeed

Footnotes

  1. 31 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 (331c920) during the generation of this report, so 800bc17 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant