WebAssembly / WebAssembly/binaryen

wasm-opt performance

Open
#4,619 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

I am working what would expect to be a rather large c++ code based and compiling for webassembly

One thing i have noticed during the process is the performance of wasm-opt across my .wasm file. I am wondering if there is anything i can do to help profile where the bottlenecks are in wasm-opt and if we can address them.

Here is breakdown of file size, and run time of wasm-opt
baseline perf.wasm -> 419.88MB
O0 38.6 MB
O1 33.6 MB
O2 29.3 MB
O3 30.7 MB
Os 28.7 MB <- Our current build optimization level
Oz 28.3 MB

I am using the following script
ls -l perf.wasm
for OPT in 0 1 2 3 s z
do
  time /root/emsdk/upstream/bin/wasm-opt -O$OPT --strip-dwarf --post-emscripten --low-memory-unused --zero-filled-memory --strip-debug --strip-producers \
    perf.wasm -o perfO$OPT.wasm --mvp-features --enable-threads --enable-mutable-globals --enable-bulk-memory --enable-sign-ext
  ls -l perfO$OPT.wasm
  sleep 15s
done

Here is the output

-rw-r--r-- 1 root root 440277504 Apr 27 08:52 perf.wasm

real    0m12.978s
user    0m17.046s
sys     0m1.136s
-rw-r--r-- 1 root root 40548421 Apr 27 09:21 perfO0.wasm

real    0m28.735s
user    1m47.963s
sys     0m1.555s
-rw-r--r-- 1 root root 35313836 Apr 27 09:22 perfO1.wasm

real    1m44.731s
user    7m1.825s
sys     0m1.861s
-rw-r--r-- 1 root root 30765732 Apr 27 09:24 perfO2.wasm

real    2m15.277s
user    11m46.021s
sys     0m1.842s
-rw-r--r-- 1 root root 32263192 Apr 27 09:26 perfO3.wasm

real    2m2.222s
user    9m3.411s
sys     0m1.860s
-rw-r--r-- 1 root root 30136226 Apr 27 09:29 perfOs.wasm

real    1m59.970s
user    9m23.343s
sys     0m2.571s
-rw-r--r-- 1 root root 29763508 Apr 27 09:31 perfOz.wasm

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported wasm-opt timings with the provided perf.wasm input and optimization script. Profile the wasm-opt entry point across the listed -O0 through -Oz runs to identify the bottleneck; done means the costly operation is isolated and a concrete optimization scope is agreed.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
compilers, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.