Tips on reducing WASM file size with Emscripten
Posted on July 1, 2019 • 1 minutes • 119 words
Optimize for size over performance
If size is more important than performance, you can use -Os
flag.
I tried with camaro and the file size reduce from 176KB down to 130KB. It’s worth a try.
Disable assertion, debug
Try adding these flags: -s ASSERTIONS=0
and -DNDEBUG
to emcc.
Using emmaloc
Try using emmalloc
which is a smaller malloc version available in emcc by adding -s 'MALLOC="emmalloc"'
flag
Closure
Using --closure 1
flag may also help as well.
Remove unnecessary dependencies
Try not to import unnecessary libs in C++. Eg: don’t forget to remove iostream
if you only use it for debugging with std::cout
Emscripten has a whole section about this, do read this to stay up to date.
https://emscripten.org/docs/optimizing/Optimizing-Code.html#code-size