Skip to content

[wasm-split] Precompute ownership info (NFC) - #8986

Open
aheejin wants to merge 1 commit into
mainfrom
wasm_split_owning_modules
Open

[wasm-split] Precompute ownership info (NFC)#8986
aheejin wants to merge 1 commit into
mainfrom
wasm_split_owning_modules

Conversation

@aheejin

@aheejin aheejin commented Aug 11, 2026

Copy link
Copy Markdown
Member

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, this reduces the running time of wasm-split by 17% for acx_gallery (30s -> 25s) and by 33% for essentials (230s -> 153s).

Suggested in #8832 (comment).

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, this reduces the running time of wasm-split by 17% for acx_gallery
(30s -> 25s) and by 33% for essentials (230s -> 153s).

Suggested in
#8832 (comment).
@aheejin
aheejin requested a review from tlively August 11, 2026 21:00
@aheejin
aheejin requested a review from a team as a code owner August 11, 2026 21:00
aheejin added a commit that referenced this pull request Aug 12, 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

Combining with #8986, acx_gallery's running time improved by 50.3% (30s
-> 15s), and essentials by 60.8% (230s -> 90s). (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.

1 participant