Does optimizing for speed (-O3 / -O) actually beat optimizing for size (-Os / -Oz / -Osize)?
Measured across three setups:
- WebAssembly (
wasm/,engines/) — Benchmarks Game ports run through Binaryenwasm-optat-O3,-Os, and-Oz(plus source-level size flags), timed in V8 (d8, TurboFan and Liftoff), JavaScriptCore, and Wasmtime. - Native Benchmarks Game (
native/) — C, C++, Rust, and Swift ports compiled natively on macOSarm64and Linuxx86_64, with paired runs and root-cause writeups for the cases where size builds won. - Compilers (
compilers/) — Four JPL compilers (Rust and Zig) compiled at-O3/-Os/-Oz, timed warm and cold onarm64andx86_64.
- WebAssembly (
wasm-opt -Ozvs-O3, V8/d8, 108 language × program pairs):Oz / O3run time 0.987 (95% CI[0.971, 0.998]), binary size 0.962 ([0.936, 0.983]).-O3bought no speed over-Oz; where they differed,-Ozusually won because-O3's partial inlining blew V8's inlining budget. - Native Benchmarks Game (
arm64&x86_64, paired runs):-O3won almost everywhere (54/70 losses for small builds on Mac, 57/70 on x86). Four real Macarm64wins (knucleotideC++-Os0.70×,binarytreesC++-Oz0.89×,spectralnormSwift-Osize0.93×,fannkuchreduxC-Oz0.95×) came down to specific inlining, register-save, scheduling, and/2lowering quirks — documented in native/ANOMALIES.md. - Compilers (warm & cold, paired runs):
-O3won across the board once measurement artifacts were removed (hyperfine post-purge launch overhead on macOS; Hyper-V free-page reporting under WSL2 on x86). Details in compilers/FINDINGS.md.
programs/— Benchmarks Game ports (copied from utu).wasm/— Binaryenwasm-optharness, stats script, anddata/.engines/— Multi-engine Wasm runner (liftoff,jsc,wasmtime) andall.json.native/— Native build/timing harness, SIMD shims,data/, ANOMALIES.md, and minimal repros inanomalies/.compilers/— Compiler timing harness (timeit.c,accurate.sh),data/, and FINDINGS.md.analysis/— Summary scripts (compilers.py,native.py,export_rows.py) andaccurate-rows.json.
node wasm/stats.mjs
python3 analysis/native.py
python3 analysis/compilers.py arm64 x86Earlier raw logs and intermediate experiment files are preserved on the old branch.