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

  1. Branch Hints

    Wasm gains likely/unlikely branch hints. Compilers can produce code that lays out the hot path inline, improving CPU branch prediction.

  2. Hex Inspector

    Hand-assembled side-by-side: identical Wasm logic, one with the metadata.code.branch_hint custom section, one without. Validate and instantiate both to confirm engines silently accept the hint bytes.

  3. Branch bench

  4. Wasm Branch Optimizer

    Three C code patterns — error guard, hot-path loop, rare debug logging — shown with and without @likely/@unlikely hints. 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.

references