Skip to content

[NFC] Improve SimplifyLocals compile-time performance#8604

Open
Changqing-JING wants to merge 1 commit intoWebAssembly:mainfrom
Changqing-JING:opt/compile-speed-4
Open

[NFC] Improve SimplifyLocals compile-time performance#8604
Changqing-JING wants to merge 1 commit intoWebAssembly:mainfrom
Changqing-JING:opt/compile-speed-4

Conversation

@Changqing-JING
Copy link
Copy Markdown
Contributor

@Changqing-JING Changqing-JING commented Apr 15, 2026

The checkInvalidations function in SimplifyLocals had O(N × S) complexity, iterating all sinkables for every visited expression. This PR adds reverse indices (localReadBySinkable_, localWrittenBySinkable_, heavySinkables_) so that checkInvalidations only examines sinkables whose effects actually conflict with the current expression. The Sinkables map and localsRead/localsWritten sets are also changed from ordered to unordered containers for faster lookups. A new hasNonLocalOrderingEffects() helper is added to EffectAnalyzer (composing existing helpers like writesGlobalState() and readsMutableGlobalState()) so the classification stays in sync automatically when new effect types are added.

Benchmark data
Use the wasm file in
#7319 (comment)

Note: don't run benchmark with -Oz, use --simplify-locals can save time.
Before this PR

time ./build/bin/wasm-opt --simplify-locals --enable-bulk-memory --enable-multivalue --enable-reference-types --enable-gc --enable-tail-call --enable-exception-handling  -o /dev/null ./test3.wasm

real    0m42.423s
user    9m45.063s
sys     0m44.099s

In this PR

time ./build/bin/wasm-opt --simplify-locals --enable-
bulk-memory --enable-multivalue --enable-reference-types --enable-gc --enable-tail-call --enable-e
xception-handling  -o /dev/null ./test3.wasm

real    0m29.725s
user    6m25.124s
sys     0m30.590s

@Changqing-JING Changqing-JING requested a review from a team as a code owner April 15, 2026 06:19
@Changqing-JING Changqing-JING requested review from kripken and removed request for a team April 15, 2026 06:19
@Changqing-JING Changqing-JING marked this pull request as draft April 15, 2026 06:20
@Changqing-JING Changqing-JING changed the title Improve SimplifyLocals compile-time performance [NFC] Improve SimplifyLocals compile-time performance Apr 15, 2026
@Changqing-JING Changqing-JING marked this pull request as ready for review April 15, 2026 07:13
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.

1 participant