Stream: git-wasmtime

Topic: wasmtime / PR #12234 Translate `global.get`s of defined, ...


view this post on Zulip Wasmtime GitHub notifications bot (Dec 31 2025 at 23:04):

fitzgen opened PR #12234 from fitzgen:global-get-of-defined-immutable-globals to bytecodealliance:main:

When a global is both defined locally within the module and immutable, we can emit a constant value, rather than a vmctx load, when translating a global.get of that global from Wasm to CLIF.

This provides a surprising amount of speed ups on sightglass benchmarks, including a 1.12x speed up for the new spidermonkey-json benchmark:

<details>

execution :: instructions-retired :: benchmarks/spidermonkey/spidermonkey-json.wasm

  Δ = 159602263.67 ± 211.65 (confidence = 99%)

  const-globals.so is 1.12x to 1.12x faster than main.so!

  [1293484118 1293484381.73 1293485153] const-globals.so
  [1453086549 1453086645.40 1453087556] main.so

execution :: instructions-retired :: benchmarks/spidermonkey/spidermonkey-regex.wasm

  Δ = 13152398.33 ± 57.47 (confidence = 99%)

  const-globals.so is 1.03x to 1.03x faster than main.so!

  [387099586 387099699.10 387099862] const-globals.so
  [400251990 400252097.43 400252306] main.so

execution :: instructions-retired :: benchmarks/spidermonkey/spidermonkey-markdown.wasm

  Δ = 15034097.07 ± 10655.88 (confidence = 99%)

  const-globals.so is 1.02x to 1.02x faster than main.so!

  [763628883 763651147.87 763678416] const-globals.so
  [778659903 778685244.93 778735782] main.so

execution :: instructions-retired :: benchmarks/hashset/benchmark.wasm

  Δ = 44391.93 ± 11.74 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [256202796 256202806.90 256202889] const-globals.so
  [256247196 256247198.83 256247206] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-aead_aes256gcm.wasm

  Δ = 0.03 ± 0.00 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [231 231.03 232] const-globals.so
  [231 231.00 231] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-secretbox_easy.wasm

  Δ = 5.10 ± 0.00 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [142584 142584.00 142584] const-globals.so
  [142584 142589.10 142736] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-core4.wasm

  Δ = 0.03 ± 0.00 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [1712 1712.00 1712] const-globals.so
  [1712 1712.03 1713] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-aead_xchacha20poly1305.wasm

  Δ = 14.03 ± 5.04 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [1749396 1749410.20 1749418] const-globals.so
  [1749396 1749396.17 1749397] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-chacha20.wasm

  Δ = 20.77 ± 0.52 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [3669797 3669797.77 3669802] const-globals.so
  [3669818 3669818.53 3669819] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-stream4.wasm

  Δ = 0.03 ± 0.00 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [7704 7704.00 7704] const-globals.so
  [7704 7704.03 7705] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-kdf_hkdf.wasm

  Δ = 28.63 ± 20.56 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [11832986 11832986.07 11832987] const-globals.so
  [11833007 11833014.70 11833231] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-kx.wasm

  Δ = 27.03 ± 8.96 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [42174047 42174047.80 42174049] const-globals.so
  [42174071 42174074.83 42174169] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-box_easy.wasm

  Δ = 7.03 ± 5.85 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [14607649 14607657.37 14607674] const-globals.so
  [14607649 14607650.33 14607656] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-scalarmult_ed25519.wasm

  Δ = 15.13 ± 6.00 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [69623939 69623956.20 69623967] const-globals.so
  [69623939 69623941.07 69623948] main.so

execution :: instructions-retired :: benchmarks/shootout/shootout-memmove.wasm

  Δ = 10.27 ± 7.81 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [127094323 127094334.60 127094359] const-globals.so
  [127094322 127094324.33 127094328] main.so

execution :: instructions-retired :: benchmarks/rust-html-rewriter/benchmark.wasm

  Δ = 1.00 ± 0.79 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [19351722 19351723.50 19351725] const-globals.so
  [19351723 19351724.50 19351728] main.so

execution :: instructions-retired :: benchmarks/shootout/shootout-switch.wasm

  Δ = 6.10 ± 4.85 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [162346015 162346025.03 162346043] const-globals.so
  [162346015 162346018.93 162346029] main.so

execution :: instructions-retired :: benchmarks/bz2/benchmark.wasm

  Δ = 7.00 ± 6.01 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [221270644 221270655.00 221270687] const-globals.so
  [221270643 221270648.00 221270660] main.so

execution :: instructions-retired :: benchmarks/shootout/shootout-keccak.wasm

  Δ = 1.27 ± 1.27 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [77020158 77020160.20 77020167] const-globals.so
  [77020158 77020158.93 77020161] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-sign.wasm

  Δ = 142.13 ± 116.31 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [10962329294 10962329441.17 10962329786] const-globals.so
  [10962329386 10962329583.30 10962330163] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-pwhash_scrypt_ll.wasm

  Δ = 9.20 ± 7.92 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [869339510 869339515.17 869339524] const-globals.so
  [869339511 869339524.37 869339568] main.so

execution :: instructions-retired :: benchmarks/gcc-loops/benchmark.wasm

  Δ = 784.27 ± 309.85 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [74362830008 74362830127.20 74362830790] const-globals.so
  [74362830308 74362830911.47 74362832876] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-stream2.wasm

  Δ = 5.60 ± 4.20 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [626659894 626659899.27 626659912] const-globals.so
  [626659896 626659904.87 626659922] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-pwhash_scrypt.wasm

  Δ = 98.67 ± 82.17 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [13152494757 13152494926.27 13152495383] const-globals.so
  [13152494768 13152494827.60 13152495097] main.so

execution :: instructions-retired :: benchmarks/shootout/shootout-ratelimit.wasm

  Δ = 1.27 ± 0.97 (confidence = 99%)

  const-globals.so is 1.00x to 1.00x faster than main.so!

  [175149590 175149591.37 175149594] const-globals.so
  [175149590 175149592.63 175149597] main.so

execution :: instructions-retired :: benchmarks/shootout/shootout-sieve.wasm

  Δ = 11.50 ± 9.59 (confidence = 99%)

  main.so is 1.00x to 1.00x faster than const-globals.so!

  [3233944543 3233944562.03 3233944615] const-globals.so
  [3233944542 3233944550.53 3233944561] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-box_easy2.wasm

  No difference in performance.

  [49726677 983789516.60 2793874378] const-globals.so
  [75238587 877793884.97 1876844760] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-sodium_utils.wasm

  No difference in performance.

  [111905571 177945377.97 251390843] const-globals.so
  [109756498 161402407.73 241287377] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-secretstream.wasm

  No difference in performance.

  [692182 1151252.33 1525086] const-globals.so
  [537504 1069691.37 1567439] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-secretstream_xchacha20poly1305.wasm

  No difference in performance.

  [558450 1058015.77 1495400] const-globals.so
  [727777 1049762.87 1607655] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-secretbox_easy2.wasm

  No difference in performance.

  [820755 544888840.37 1741297134] const-globals.so
  [1905303 542356897.47 1846687120] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-keygen.wasm

  No difference in performance.

  [86869 87301.00 92053] const-globals.so
  [86893 86979.40 89485] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-aead_aegis256.wasm

  No difference in performance.

  [121347810 124839812.40 127901128] const-globals.so
  [121113415 124532015.60 127363026] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-metamorphic.wasm

  No difference in performance.

  [253403413 255557329.33 257742703] const-globals.so
  [253413445 255203119.77 257113695] main.so

execution :: instructions-retired :: benchmarks/libsodium/libsodium-aead_aegis128l.wasm

  No difference in performance.

  [110612323 112358979.77 115589830] const-globals.so
  [108810849 112481902.83 114989404] main.so

execution
[message truncated]

view this post on Zulip Wasmtime GitHub notifications bot (Dec 31 2025 at 23:04):

fitzgen requested abrown for a review on PR #12234.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 31 2025 at 23:04):

fitzgen requested wasmtime-compiler-reviewers for a review on PR #12234.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 31 2025 at 23:04):

fitzgen requested alexcrichton for a review on PR #12234.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 31 2025 at 23:04):

fitzgen requested wasmtime-core-reviewers for a review on PR #12234.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 03 2026 at 01:32):

cfallin submitted PR review:

This is great; thanks for the optimization!

As an aside, I think these global.gets arise because of -fPIC support in the Wasm; I wonder whether the overhead was ever measured when that was introduced? I also recall having to build support into weval for this same thing (to resolve some loads that needed to be constants).

For the benchmark results: would you mind running with cycles as well? instructions-retired is nice as a less noisy measurement but (as I'm sure you know) translates into actual runtime via the IPC ratio which can vary considerably (and sometimes a bigger shift in insts-retired can translate to a smaller shift in cycles because a big modern core had extra parallelism available and soaked up the extra insts). Not that we shouldn't take this if that shifts the speedup ratio, but I'm curious how to map it back into the wallclock speedup realm.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 03 2026 at 01:32):

cfallin created PR review comment:

Alternately, we could somehow reuse our Wasm opcode-to-CLIF translation and our constant propagation rules in Cranelift, which might be attractive the more operators are allowed here (I haven't followed the extended constant ops stuff closely). That's especially attractive if we want e.g. weird floating point ops to be handled, without duplicating subtle logic.

That said I'm totally happy seeing just the "match on a const op and nothing else" logic here and I suspect it'll serve us well for a while.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 17:30):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 17:30):

alexcrichton created PR review comment:

Could this also get deduplicated with our preexisting fast path in const-eval?

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 17:37):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 17:37):

alexcrichton created PR review comment:

One possible future extension (not for this PR of course) would be to do something similar to the inliner to record that, even for imported globals, if the definition is in-wasm itself then we can also use the constant value. (e.g. dynamic-linking-using modules in components have this use case a lot)

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 19:06):

fitzgen commented on PR #12234:

For the benchmark results: would you mind running with cycles as well?

Here are the statistically significant results for the union of the default and spidermonkey suites:

execution :: cycles :: benchmarks/spidermonkey/spidermonkey-regex.wasm

  Δ = 13784417.62 ± 1601175.99 (confidence = 95%)

  const-globals.so is 1.12x to 1.15x faster than main.so!

  [95605340 102055302.78 113076016] const-globals.so
  [108817028 115839720.40 130669995] main.so

execution :: cycles :: benchmarks/spidermonkey/spidermonkey-json.wasm

  Δ = 21313175.50 ± 3974537.59 (confidence = 95%)

  const-globals.so is 1.04x to 1.06x faster than main.so!

  [430192877 447371155.90 481142771] const-globals.so
  [453513124 468684331.40 498712186] main.so

execution :: cycles :: benchmarks/spidermonkey/spidermonkey-markdown.wasm

  Δ = 7808152.48 ± 3422053.66 (confidence = 95%)

  const-globals.so is 1.02x to 1.04x faster than main.so!

  [243578150 256543404.70 290894646] const-globals.so
  [250816324 264351557.18 291022356] main.so

compilation :: cycles :: benchmarks/spidermonkey/spidermonkey-json.wasm

  Δ = 126839166.33 ± 68413737.76 (confidence = 95%)

  const-globals.so is 1.01x to 1.03x faster than main.so!

  [5245610853 5681924950.25 6377651439] const-globals.so
  [5335942910 5808764116.58 6205362989] main.so

compilation :: cycles :: benchmarks/spidermonkey/spidermonkey-regex.wasm

  Δ = 76636378.65 ± 63967936.99 (confidence = 95%)

  const-globals.so is 1.00x to 1.02x faster than main.so!

  [5273504161 5722946594.87 6097943552] const-globals.so
  [5364351697 5799582973.52 6282306166] main.so

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 19:12):

fitzgen created PR review comment:

Filed https://github.com/bytecodealliance/wasmtime/issues/12242 to track this.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 19:12):

fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 19:16):

fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 19:16):

fitzgen created PR review comment:

Could this also get deduplicated with our preexisting fast path in const-eval?

Filed this as https://github.com/bytecodealliance/wasmtime/issues/12243 because it requires figuring out how we want to dedupe code across crates that can't share existing code without us doing some kind of refactor first.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 05 2026 at 19:47):

fitzgen merged PR #12234.


Last updated: Jan 09 2026 at 13:15 UTC