v137 · webassembly
WebAssembly Branch Hints
Improves the performance of compiled WebAssembly code by informing the engine that a particular branch instruction is very likely to take a specific path.
concepts
-
Branch Hints
Wasm gains likely/unlikely branch hints. Compilers can produce code that lays out the hot path inline, improving CPU branch prediction.
-
Hex Inspector
Hand-assembled side-by-side: identical Wasm logic, one with the
metadata.code.branch_hintcustom section, one without. Validate and instantiate both to confirm engines silently accept the hint bytes. -
Branch bench
-
Wasm Branch Optimizer
Three C code patterns — error guard, hot-path loop, rare debug logging — shown with and without
@likely/@unlikelyhints. See the corresponding WAT annotations and run a JS simulation benchmark to observe potential timing differences.Run the same hot loop with and without the branch hint at three workloads / three cold-path probabilities. Reports per-run timings, median, and a winner-by-percent summary.
why it shipped
This proposal has been voted to phase 4 in the WebAssembly CG in June 2024 and Chrome is preparing shipment of it.