RajaBabu15 opened PR #15104 from RajaBabu15:hostcall-fuel-store-fuel to bytecodealliance:main:
Closes #14430
Implements the approach agreed in the issue: optionally charge Store fuel for the work done while lifting guest values into the host, at
LiftContext::consume_fuel.
- New opt-in
Store::set_hostcall_fuel_consumes_store_fuel(bool)(plus getter andStoreContextMutmirrors). Off by default; only has an effect withConfig::consume_fuel(true).- When enabled, each unit of hostcall fuel consumed during a lift also consumes one unit of Store fuel, charged before the copy happens. If Store fuel runs out, the remaining fuel is consumed and the lift traps with
Trap::OutOfFuel. Charges already made earlier in the same lift stay charged.- Lowering is not charged, per the discussion. Hostcall fuel consumed in compiled FACT adapters / component-to-component streams (#15030) is also not charged here.
- The fuel math reuses the existing
get_fuel/set_fuelhelpers. A charge that fits in the active (injected) window only bumps that counter, leaving the reserve and the async yield cadence alone.- When the flag is off, the only cost is one
Optioncheck inconsume_fuel.Tests:
tests/all/component_model/import.rs: flag off (default), flag on, flag on with too little fuel (OutOfFuel, fuel is 0, host fn never runs), and flag on withoutConfig::consume_fuel.- Unit tests for the new fuel helper in
runtime/store.rs.- Locally on aarch64 macOS:
component_model(264),fuel(75) andwasmtime --lib(183) tests pass; fmt and clippy are clean. The C API was not built locally (no cmake).Open questions:
- Naming, and whether this belongs on
Store(next toset_hostcall_fuel) or onConfig.- The setter is currently a silent no-op without
Config::consume_fuel; should it return an error likeset_fueldoes?- If one charge is larger than the active fuel window, the remaining fuel is redistributed, which restarts the async-yield countdown. Is that acceptable, or should it leave the counter positive so the next wasm fuel check handles it?
:robot: Generated with Claude Code
RajaBabu15 requested fitzgen for a review on PR #15104.
RajaBabu15 removed the review request for wasmtime-core-reviewers from PR #15104.
RajaBabu15 requested wasmtime-core-reviewers for a review on PR #15104.
github-actions[bot] added the label wasmtime:api on PR #15104.
fitzgen commented on PR #15104:
This PR appears to be in violation of our AI tool policy. If you do not believe that is true, you may state your case.
RajaBabu15 commented on PR #15104:
You're right. I opened this before I understood the fuel accounting well enough to defend it. I'm closing it and will return with something smaller that I can fully explain.
:cross_mark: RajaBabu15 closed without merge PR #15104.
RajaBabu15 edited PR #15104:
Closes #14430
Implements the approach agreed in the issue: optionally charge Store fuel for the work done while lifting guest values into the host, at
LiftContext::consume_fuel.
- New opt-in
Store::set_hostcall_fuel_consumes_store_fuel(bool)(plus getter andStoreContextMutmirrors). Off by default; only has an effect withConfig::consume_fuel(true).- When enabled, each unit of hostcall fuel consumed during a lift also consumes one unit of Store fuel, charged before the copy happens. If Store fuel runs out, the remaining fuel is consumed and the lift traps with
Trap::OutOfFuel. Charges already made earlier in the same lift stay charged.- Lowering is not charged, per the discussion. Hostcall fuel consumed in compiled FACT adapters / component-to-component streams (#15030) is also not charged here.
- The fuel math reuses the existing
get_fuel/set_fuelhelpers. A charge that fits in the active (injected) window only bumps that counter, leaving the reserve and the async yield cadence alone.- When the flag is off, the only cost is one
Optioncheck inconsume_fuel.Tests:
tests/all/component_model/import.rs: flag off (default), flag on, flag on with too little fuel (OutOfFuel, fuel is 0, host fn never runs), and flag on withoutConfig::consume_fuel.- Unit tests for the new fuel helper in
runtime/store.rs.- Locally on aarch64 macOS:
component_model(264),fuel(75) andwasmtime --lib(183) tests pass; fmt and clippy are clean. The C API was not built locally (no cmake).Open questions:
- Naming, and whether this belongs on
Store(next toset_hostcall_fuel) or onConfig.- The setter is currently a silent no-op without
Config::consume_fuel; should it return an error likeset_fueldoes?- If one charge is larger than the active fuel window, the remaining fuel is redistributed, which restarts the async-yield countdown. Is that acceptable, or should it leave the counter positive so the next wasm fuel check handles it?
RajaBabu15 edited PR #15104:
Closes #14430.
Adds an opt-inStore::set_hostcall_fuel_consumes_store_fuel, so lifting guest values also consumes Wasm fuel.
It is off by default and needsConfig::consume_fuel; lowering is not charged.
Fuel is charged before the copy; running out consumes the rest and traps withOutOfFuel.
Tests cover the flag off, on, on with too little fuel, and without engine fuel.
RajaBabu15 edited a comment on PR #15104:
Closing this: I opened it before I understood the fuel accounting well enough to defend it. I will come back with something smaller that I can explain.
Last updated: Nov 19 2026 at 20:05 UTC