Hello! I am working on my own virtual machine and have a question about how fuel consumption is currently implemented and a feature request regarding the same.
From my research I understand that:
I would prefer if something like this could be implemented in wasmtime:
// Instead of:
instruction_1
consume_fuel(1)
instruction_2
consume_fuel(1)
instruction_3
consume_fuel(1)
// It would be better if it was something like:
instruction_1
instruction_2
instruction_3
consume_fuel(3) // Batch at end of basic block
This would reduce the number of increment operations while still allowing fuel checks at control flow boundaries to interrupt execution when needed.
You may be interested in epoch-based interruption:
Epoch-based interruption imposes relatively low overhead on Wasm execution; it has been measured at around a 10% slowdown. It is faster than fuel-based interruption.
Dave Bakker (badeend) said:
You may be interested in epoch-based interruption:
Epoch-based interruption imposes relatively low overhead on Wasm execution; it has been measured at around a 10% slowdown. It is faster than fuel-based interruption.
I am interested in deterministic fuel metering.
I believe that this sort of batching is already implemented. The code looks like it's consume-per-op but IIRC it batches up the actual increment until some sort of side-effecting thing happens. Once a side-effecting thing happens though (e.g. loads/stores) for the determinism of fuel it needs to be flushed.
Having a tunable option for ignoring side effecting ops other than control flow might be a possibility though
Are you sure that wasmtime batches instruction increments?
Last updated: Dec 06 2025 at 06:05 UTC