Skip to content

Test/adjust fuel consumption in bulk ops#13448

Merged
cfallin merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:bulk-ops
May 22, 2026
Merged

Test/adjust fuel consumption in bulk ops#13448
cfallin merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:bulk-ops

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This commit is the final step of #13387 to add tests for all bulk operations and ensure that everything stays in sync. Notably all instructions have tests that their "infinite" version traps on out-of-fuel and additionally each version consumes a set amount of fuel. This required adjusting the fuel consumption loops as to where fuel was tweaked/flushed to ensure that fuel wasn't double-counted during loops and to also ensure that 1 fuel was consumed per-loop.

This does surface some slightly odd behavior where sometimes fuel is counted as a per-byte operation and sometimes it's counted as a per-element operation. This happens due to how the code is structured where sometimes array.fill, for example, is a memset and sometimes it's per-element. The fuel consumption of memset is byte-based, for example, while it's per-element based for the manual loop. Regardless though it's still always deterministic for a particular wasm, and notably execution will still be limited by the dynamic operation size of these instructions.

Closes #13387

This commit is the final step of bytecodealliance#13387 to add tests for all bulk
operations and ensure that everything stays in sync. Notably all
instructions have tests that their "infinite" version traps on
out-of-fuel and additionally each version consumes a set amount of fuel.
This required adjusting the fuel consumption loops as to where fuel was
tweaked/flushed to ensure that fuel wasn't double-counted during loops
and to also ensure that 1 fuel was consumed per-loop.

This does surface some slightly odd behavior where sometimes fuel is
counted as a per-byte operation and sometimes it's counted as a
per-element operation. This happens due to how the code is structured
where sometimes `array.fill`, for example, is a `memset` and sometimes
it's per-element. The fuel consumption of `memset` is byte-based, for
example, while it's per-element based for the manual loop. Regardless
though it's still always deterministic for a particular wasm, and
notably execution will still be limited by the dynamic operation size of
these instructions.

Closes bytecodealliance#13387
@alexcrichton alexcrichton requested review from a team as code owners May 22, 2026 06:04
@alexcrichton alexcrichton requested review from cfallin and removed request for a team May 22, 2026 06:04
Copy link
Copy Markdown
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Looks good!

This does surface some slightly odd behavior where sometimes fuel is counted as a per-byte operation and sometimes it's counted as a per-element operation. This happens due to how the code is structured where sometimes array.fill, for example, is a memset and sometimes it's per-element. The fuel consumption of memset is byte based, for example, while it's per-element based for the manual loop. Regardless though it's still always deterministic for a particular wasm, and notably execution will still be limited by the dynamic operation size of these instructions.

That seems fine to me; we've never made any guarantees about what one unit of fuel means (so we're free to increase or decrease "fuel efficiency1" as our needs require that...)

Footnotes

  1. drive an electric Wasmtime today for incredible fuel efficiency! inquire inside for conditions of offer

@cfallin cfallin added this pull request to the merge queue May 22, 2026
Merged via the queue into bytecodealliance:main with commit 4030e4f May 22, 2026
51 checks passed
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.

Should we add fuel/epoch checks into the middle of {array,memory,table}.{fill,copy,init}?

2 participants