Skip to content

Mark the out-of-gas block cold - #15537

Queued
0xbe7a wants to merge 1 commit into
bytecodealliance:mainfrom
0xbe7a:fuel-cold-out-of-gas
Queued

0xbe7a wants to merge 1 commit into
bytecodealliance:mainfrom
0xbe7a:fuel-cold-out-of-gas

Conversation

@0xbe7a

@0xbe7a 0xbe7a commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

The fuel check branches to a block that calls the out_of_gas builtin, which runs only when fuel is exhausted. The epoch check already marks its equivalent new_epoch block cold; do the same for the fuel check so the slow path is moved out of line and the fast path falls through.

Execution cycles with fuel (-Wfuel=1000000000000000000), pca-20-min suite, main 7e00d84d7 vs this branch, Sightglass effect size at 99% confidence.

Geomean (29 benchmarks): this branch is 1.05–1.07× faster on Zen 5 (AMD EPYC 4545P) and 1.08–1.10× / 1.08–1.09× faster on an Apple M3 Pro (two runs with the engine order reversed).

Control: with -Wepoch-interruption=y instead of fuel both builds compile to identical code. Sightglass finds no geomean difference in compilation, instantiation or execution on either machine; on the M3 no single benchmark differs, on Zen 5 three differ by at most 2% (the per-benchmark noise floor there).

Compile time: with fuel, compilation takes 1–3% more cycles on Zen 5 and 1.5–2% more on the M3 (both orders), while retired instructions in the compilation phase grow by only 0.13% (Zen 5).

Zen 5 per benchmark
Benchmark This branch vs main
java-navier-stokes 1.41× faster
hex-simd 1.30–1.36× faster
rust-json 1.15–1.18× faster
libsodium-keygen 1.11× faster
intgemm-simd 1.10–1.11× faster
wat-bytecode-interp 1.10× faster
hashset 1.09–1.10× faster
gcc-loops 1.09× faster
shootout-xchacha20 1.09× faster
libsodium-core5 1.09× faster
shootout-sieve 1.06–1.08× faster
shootout-switch 1.06–1.07× faster
starlingmonkey-markdown 1.04–1.05× faster
tinygo-regex 1.03× faster
shootout-heapsort 1.02× faster
cm-online-stats 1.01–1.02× faster
kotlin-richards 1.01–1.02× faster
ocaml-raytrace 1.01–1.02× faster
dart-deltablue 1.00–1.01× faster
shootout-keccak 1.00–1.01× faster
hoot-earley-boyer no significant difference
richards no significant difference
rust-protobuf no significant difference
splay no significant difference
shootout-memmove 1.00–1.01× slower
dotnet-raytracer 1.00–1.02× slower
libsodium-siphashx24 1.02× slower
rust-wasmprinter 1.02× slower
libsodium-hash3 1.02× slower
execution :: cycles :: Geomean (29 benchmarks)

    libwasmtime_bench_api-cold.so (-Wfuel=1000000000000000000) is 1.05x to 1.07x faster than libwasmtime_bench_api-main.so (-Wfuel=1000000000000000000)!
    (confidence = 99%, df = 1824.8)

    ┌─────────────┬────────────┬────────────────────────────────────────────────────────────┐
    │ Geomean     │ Benchmarks │ Engine                                                     │
    ├─────────────┼────────────┼────────────────────────────────────────────────────────────┤
    │ 20573970.67 │ 29         │ libwasmtime_bench_api-cold.so (-Wfuel=1000000000000000000) │
    ├─────────────┼────────────┼────────────────────────────────────────────────────────────┤
    │ 21767918.97 │ 29         │ libwasmtime_bench_api-main.so (-Wfuel=1000000000000000000) │
    └─────────────┴────────────┴────────────────────────────────────────────────────────────┘
Apple M3 Pro per benchmark
Benchmark Run 1 (main first) Run 2 (branch first)
hex-simd 1.71–2.27× faster 1.76–1.91× faster
shootout-sieve 1.47–1.49× faster 1.48–1.49× faster
shootout-xchacha20 1.19–1.20× faster 1.195–1.198× faster
hashset 1.18–1.20× faster 1.19–1.20× faster
wat-bytecode-interp 1.15–1.16× faster 1.15–1.16× faster
libsodium-keygen 1.13–1.14× faster 1.13–1.14× faster
libsodium-siphashx24 1.12–1.14× faster 1.138–1.141× faster
intgemm-simd 1.09–1.14× faster 1.07–1.09× faster
java-navier-stokes 1.09–1.11× faster 1.085–1.088× faster
richards 1.07–1.10× faster 1.08–1.10× faster
gcc-loops 1.07–1.08× faster 1.077–1.080× faster
rust-json 1.05–1.07× faster 1.06–1.07× faster
starlingmonkey-markdown 1.04–1.07× faster 1.04–1.06× faster
libsodium-core5 1.04–1.05× faster 1.047–1.050× faster
shootout-heapsort 1.04–1.05× faster 1.04–1.05× faster
libsodium-hash3 1.035–1.041× faster 1.036–1.040× faster
shootout-switch 1.02–1.04× faster 1.03–1.04× faster
rust-protobuf 1.02–1.05× faster 1.01–1.03× faster
rust-wasmprinter 1.01–1.02× faster 1.005–1.014× faster
dotnet-raytracer 1.01–1.02× faster 1.005–1.013× faster
splay no significant difference no significant difference
hoot-earley-boyer no significant difference no significant difference
tinygo-regex no significant difference no significant difference
shootout-memmove no significant difference no significant difference
kotlin-richards no significant difference no significant difference
cm-online-stats 1.00–1.01× slower 1.002–1.004× slower
shootout-keccak 1.007–1.012× slower 1.007–1.009× slower
dart-deltablue 1.006–1.013× slower 1.006–1.011× slower
ocaml-raytrace 1.01–1.02× slower 1.01–1.02× slower

The fuel check branches to a block that calls the `out_of_gas` builtin,
which runs only when fuel is exhausted. The epoch check already marks
its equivalent `new_epoch` block cold; do the same for the fuel check
so the slow path is moved out of line and the fast path falls through.
@0xbe7a
0xbe7a requested review from a team as code owners December 3, 2026 13:07
@0xbe7a
0xbe7a requested review from cfallin and removed request for a team December 3, 2026 13:07

@cfallin cfallin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic discovery -- thanks so much!

@cfallin
cfallin added this pull request to the merge queue Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants