Why does wasm-opt consume all cores?

When compiling a Rust crate to WASM in release mode, there is a utility being used called wasm-opt that, when called, ramps up my CPU like almost no software I've ever seen*: it has work for all cores, which is quite a feat since I have 16 of them. In addition, it can keep all those cores fed for roughly 3-4 minutes straight.

So I'm wondering: what kinds of optimizations does wasm-opt perform that consume so much computing power?

*exceptions are compiling a crate that has a lot of (transitive) Rust dependencies, and (if I were so inclined) video rendering.

I don't know of any documentation on describing all the optimization passes wasm-opt does, but the source is public?

In particular, each file in https://github.com/WebAssembly/binaryen/tree/master/src/passes implements a different optimization pass. If you're interested, the names of each file are fairly descriptive (things like "Inlining" and "DeadCodeElimination", "MergeBlocks", etc.).

binaryen is essentially an entire optimizing compiler, and the wasm-opt frontend just happens to compile from WASM to WASM.

1 Like

Binaryen uses a thread pool to optimize all functions in parallel:

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.