Code Size Optimization

Command / setting Optimize for size Rust opt-level = "z", lto = true, codegen-units = 1, panic = "abort", strip = true. Emscripten -Oz.

wasm-opt -Oz --strip-debug --strip-producers in.wasm -o out.wasm Remove debug info wasm-tools strip, --strip-debug

twiggy (twiggy top, twiggy dominators, twiggy paths), wasm-objdump -h, wasm-size Remove unused code

wasm-snip (replace functions with unreachable), wasm-metadce, careful export lists Avoid heavy dependencies

No format!/std::fmt in tiny Rust builds, avoid regex/serde when unnecessary, use #![no_std] + a small allocator (lol_alloc, talc)

AssemblyScript --runtime stub/minimal, TinyGo instead of Go, -sMALLOC=emmalloc in Emscripten

--closure 1 (Emscripten), wasm-bindgen --target web (no bundler overhead), tree shaking

Serve with Brotli (Content-Encoding: br). Wasm compresses ~3–4×.

Dynamic linking/side modules (-sMAIN_MODULE/SIDE_MODULE), wasm-split, lazy-load features

Managed languages avoid shipping their GC

twiggy top -n 20 pkg/app_bg.wasm
wasm-opt -Oz pkg/app_bg.wasm -o pkg/app_bg.wasm
ls -la pkg/*.wasm && brotli -c pkg/app_bg.wasm | wc -c