Skip to content

feat(vm): escaped functions cap during preparation#16050

Draft
jakmeier wants to merge 2 commits into
near:masterfrom
jakmeier:wasmtime_limit_escaped_functions
Draft

feat(vm): escaped functions cap during preparation#16050
jakmeier wants to merge 2 commits into
near:masterfrom
jakmeier:wasmtime_limit_escaped_functions

Conversation

@jakmeier

Copy link
Copy Markdown
Contributor

Wasmtime limits the core instance size, whose size increases with the
number of escaped functions.

To avoid running into it at load time, this introduces a limit at
preparation time. This requires counting escaped functions in the
preparation phase and if that breaches the configured limit, a new error
kind is retured as a CompilationError::PrepareError.

Gated behind the unstable nightly version 157 for stabilization together
with all other limits regarding the core instance size.

jakmeier added 2 commits July 10, 2026 17:01
The VM currently has not explicit limit on declared Wasm globals in a contract.
However, `MAX_CORE_INSTANCE_SIZE = 1MiB` acts as an implicit limit today.

This PR sets the limit to 100k global, which would add 1.6MB to the core
instance size, thus  is less restrictive than the existing limit.

A follow-up PR will make this limit stricter and combine it with other limits
that contribute to MAX_CORE_INSTANCE_SIZE. But the goal is to introduce
each limit in a separate PR before combining them.
Wasmtime limits the core instance size, whose size increases with the
number of escaped functions.

To avoid running into it at load time, this introduces a limit at
preparation time. This requires counting escaped functions in the
preparation phase and if that breaches the configured limit, a new error
kind is retured as a CompilationError::PrepareError.

Gated behind the unstable nightly version 157 for stabilization together
with all other limits regarding the core instance size.
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.

1 participant