Skip to content

Conversation

kripken
Copy link
Member

@kripken kripken commented Aug 19, 2025

The actual merging logic in wasm-merge is careful to run in linear time
(since #5709). However, validation could actually be quadratic, since we do
it after each module that we merge in. Since we validate by default, this
made wasm-merge very slow sometimes.

To fix that, validate by default once at the very end. When in pass-debug
mode, which validates after each pass, validate after each module (so we
keep the option for precise debugging of problems).

On a large testcase I am investigating (350 modules, 41 MB wasm after
merge), this makes us go from 5 minutes down to just 19 seconds. With
--no-validation, we drop to 17. (That final number is about how long it
takes to run wasm-opt 350 times to round-trip each of those modules,
so it is shows wasm-merge's merging is very fast.)

Actual diff is quite small, read without whitespace to avoid noise.

@kripken kripken requested a review from tlively August 19, 2025 23:03
@kripken kripken changed the title wasm-merge: Avoid quadratic time in validatoin wasm-merge: Avoid quadratic time in validation Aug 19, 2025
@kripken kripken changed the title wasm-merge: Avoid quadratic time in validation wasm-merge: Avoid quadratic time in validation [NFC] Aug 19, 2025
reportTypeMismatch(valid, "memory", import);
std::cerr << "index type should match.\n";
if (options.validate) {
// Make sure that the export types match the import types.
Copy link
Member

Choose a reason for hiding this comment

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

This seems pretty important, since you could have linking problems even if each module were independently valid. Is there a way to make this validation of the linked types fast enough to run by default?

Copy link
Member Author

Choose a reason for hiding this comment

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

We validate by default, so this does run by default.

It is reasonably fast - not significant in time compared to validating an entire huge module, at least.

@kripken kripken merged commit 543990b into WebAssembly:main Aug 20, 2025
16 checks passed
@kripken kripken deleted the merge.noval branch August 20, 2025 17:31
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