Tips on reducing WASM file size with Emscripten
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
Some lessons learnt after converting a native module to WebAssembly
I released my first WebAssembly module here on GitHub. Here are some lessons I learnt during the process. Please don’t take it for granted. These things might be true, or not. I’m not sure. I just worked on it for the last few days.
Cache WebAssembly instance to save some time on initialization # const Module = require('yourmodule') const mod = Module() const resolveCache = new Map() mod.onRuntimeInitialized = function() { resolveCache.
Getting started with WebAssembly
WebAssembly Binary Toolkit - Easiest way to setup WebAssembly binary toolkit. Or if you prefer to manually install it.
wat2js - Compile WebAssembly .wat files to a common js module
WebAssembly spec - WebAssembly Specification
Some examples modules
siphash24 - SipHash (2-4) implemented in pure Javascript and WebAssembly.
blake2b - Blake2b implemented in WASM
xsalsa20 - XSalsa20 implemented in Javascript and WebAssembly