demo · v137

Branch bench

Two tiny Wasm modules with the same hot loop and a rarely-taken error path. One uses the unhinted br_if; the other emits the v137 br_on_zero_hint custom section. Benchmark them at three workloads.

Heads upRequires Chrome 137+ with branch-hints enabled. If unsupported, both lanes run the unhinted module and the meter shows the no-difference baseline.
probing…
unhinted br_if

baseline

run 1
run 2
run 3
median

hex dump (header)

v137: branch hint = unlikely

with metadata.code.branch_hint

run 1
run 2
run 3
median

hex dump (header + hint section)

summary: —

the wat

(module
  (func (export "loop") (param $n i32) (result i32)
    (local $sum i32)
    (block $exit
      (loop $body
        (br_if $exit (i32.eqz (local.get $n)))      ;; (@metadata.code.branch_hint "\00") <-- unlikely
        (local.set $sum (i32.add (local.get $sum) (local.get $n)))
        (local.set $n   (i32.sub (local.get $n) (i32.const 1)))
        (br $body)))
    (local.get $sum)))

see also