Skip to content

[wasm-split] Don't use ParallelFunctionAnalysis in scanModule - #9007

Merged
aheejin merged 1 commit into
mainfrom
wasm_split_no_parallel
Aug 17, 2026
Merged

[wasm-split] Don't use ParallelFunctionAnalysis in scanModule#9007
aheejin merged 1 commit into
mainfrom
wasm_split_no_parallel

Conversation

@aheejin

@aheejin aheejin commented Aug 15, 2026

Copy link
Copy Markdown
Member

This removes the use of ParallelFunctionAnalysis within scanModule (in computeUsedNames), which scans UsedNames for each module.

I'm not 100% sure why but this improves running time at least for Dart applications. I also previously tried to use ParallelFunctionAnalysis in other functions but it resulted in slowdown so didn't do it. Maybe cache locality works against the parallelism.

This reduces running time of acx_gallery (Jul 2026) by 7.8% (30.6s -> 28.2s) essentials by 4.2% (225.1s -> 215.6s).

This removes the use of `ParallelFunctionAnalysis` within `scanModule`
(in `computeUsedNames`), which scans `UsedNames` for each module.

I'm not 100% sure why but this improves running time at least for Dart
applications. I also previously tried to use `ParallelFunctionAnalysis`
in other functions but it resulted in slowdown so didn't do it. Maybe
cache locality works against the parallelism.

This reduces running time of acx_gallery (Jul 2026) by 7.8% (30.6s ->
28.2s) essentials by 4.2% (225.1s -> 215.6s).
@aheejin
aheejin requested a review from tlively August 15, 2026 03:10
@aheejin
aheejin requested a review from a team as a code owner August 15, 2026 03:10
@aheejin aheejin changed the title [wasm-split] Don't use ParallelFunctionAnalysis for scanModule [wasm-split] Don't use ParallelFunctionAnalysis in scanModule Aug 15, 2026

@tlively tlively left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess copying all those maps serially is about as expensive as just building them up serially to begin with 🤷

@aheejin
aheejin merged commit 07a6f35 into main Aug 17, 2026
16 checks passed
@aheejin
aheejin deleted the wasm_split_no_parallel branch August 17, 2026 23:38
aheejin added a commit that referenced this pull request Aug 18, 2026
Given a module element name, many parts of the code queries for its
owning modules (where the module element has to be placed) or secondary
modules using that module element. This adds `OwnershipTracker`, which
precomputes and manages that information. All calls to `getOwner` or
`getUsingSecondaries` that required computations iterating on all
secondary modules which can be as many as thousands, has been replaced
with a call that simply returns prcomputed information.

For the Jul 2026 version of the applications received from the Dart
team, #9007 and this combined reduce the running time of wasm-split by
25% for acx_gallery (30.6s -> 22.7s) and by 40% for essentials (225.1s
-> 134.4s).

Suggested in
#8832 (comment).
aheejin added a commit that referenced this pull request Aug 18, 2026
Previously we removed module elements one by one within a loop. But
because `Module` stores a module element in both a map and a vector,
removing a single module element using `removeModuleElement` is O(N),
because it needs to shift all vector elements after it:
https://github.com/WebAssembly/binaryen/blob/302396a676433152a32375a81d71e74687c97a1b/src/wasm/wasm.cpp#L1970-L1979

This removes module elements in bulk using `removeModuleElements`, which
does the shifting only once.

https://github.com/WebAssembly/binaryen/blob/302396a676433152a32375a81d71e74687c97a1b/src/wasm/wasm.cpp#L2004-L2018

Combined with #8986 and #9007, acx_gallery's running time improved by
55.2% (30.6s -> 13.7s), and essentials by 65% (225.1s -> 78.8s). (for
Jul 2026 version)

I guess the main reason for the running time increase in #8441 was this
O(N) `removeModuleElement` called within a loop after all.
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