alexcrichton opened PR #13487 from alexcrichton:jit-module-init to bytecodealliance:main:
This commit is a large refactoring of how modules are initialized in
Wasmtime. Notably all of the work done post-allocation, but pre-start,
is now done in compiled code instead. This means that global
initialization, active table segments, passive segment evaluation, etc,
now all happens in compiled code. The primary motivation for this is to
resolve some GC-related fuzz-bugs where initialization on the host is
taking an excessively long time. A secondary motivation is to apply fuel
metering and epoch yielding to these constructs in the same manner that
normal wasm code has these applied.Much refactoring was needed in this commit to achieve this goal. Many
primitives were transitioned from runtime state to exclusively
compile-time state for example. Infrastructure was additionally added
for a new kind ofFuncKeycorresponding to this one-off-use startup
function. Overall though the net effect of this change is to mostly
delete code since so much of the runtime is now no longer necessary. An
example of this is that const-eval is now completely removed from the
runtime as the fully-general const-evaluation now happens exclusively
through compiled code.Special care was needed here for the static table and memory
initialization that Wasmtime performs. For example there's a small dance
between compile-time and run-time where at compile-time we don't know if
static data segments should be applied, and it's only at run-time where
we know if CoW is in effect. Additionally care was taken throughout this
refactoring to avoid generating this new startup function unless it's
necessary. It's hypothesized that skipping this function is going to be
a worthwhile optimization, which means that one mode of startup is
configured as "only necessary if memories sayneeds_init()". This is a
bit tricky to document and it's a bit non-standard, but it should get
the job done (and existing tests exercise this already).
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
This is something that's arguably just flat-out-wrong, and is something that I'm planning on fixing before taking this PR out of draft.
alexcrichton updated PR #13487.
alexcrichton has marked PR #13487 as ready for review.
alexcrichton requested cfallin for a review on PR #13487.
alexcrichton requested wasmtime-compiler-reviewers for a review on PR #13487.
alexcrichton requested wasmtime-core-reviewers for a review on PR #13487.
alexcrichton updated PR #13487.
alexcrichton updated PR #13487.
github-actions[bot] added the label wasmtime:api on PR #13487.
github-actions[bot] added the label wasmtime:ref-types on PR #13487.
github-actions[bot] commented on PR #13487:
Subscribe to Label Action
cc @fitzgen
<details>
This issue or pull request has been labeled: "wasmtime:api", "wasmtime:ref-types"Thus the following users have been cc'd because of the following labels:
- fitzgen: wasmtime:ref-types
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
:thumbs_up: cfallin submitted PR review:
This looks largely good to me -- nice simplification! Some thoughts below but no blockers at all.
:speech_balloon: cfallin created PR review comment:
s/t o/to/ ?
:speech_balloon: cfallin created PR review comment:
It's a little unfortunate that we have duplication between this logic and the same opcodes compiled in ordinary Wasm function bodies. I guess the compile-time state is different enough that we can't "just impl
From<ConstOp>forOpand use the existing lowerings" but I wonder how far off we are from that. In any case, anything complicated below (e.g.struct.new) is delegated to a translate helper so maybe this is fine.
:speech_balloon: cfallin created PR review comment:
s/think/thin/ ?
:speech_balloon: cfallin created PR review comment:
Would it make sense to sort
global_initializersbydef_indexand do a binary search here? I know it's in the compilation path but I always have a vague worry when I see a linear search like this...
:thumbs_up: fitzgen submitted PR review:
Nothing to add on top of Chris's comments.
alexcrichton updated PR #13487.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Good point! It's already amortized a bit where I think
make_globalhappens at most once-per-global-per-function, but the array is also already sorted so I added a binary search.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Good point yeah, and looking into this I think the main blocker is the need for a
FuncValidator<_>when translating an operator. That's not easily constructible for const-exprs currently from wasmparser's perspective. I'll file an issue on this though because it's a nice avenue for code deduplication (e.g. around fuel handling)
alexcrichton has enabled auto merge for PR #13487.
alexcrichton added PR #13487 Move most module initialization to compiled code to the merge queue.
github-merge-queue[bot] removed PR #13487 Move most module initialization to compiled code from the merge queue.
alexcrichton added PR #13487 Move most module initialization to compiled code to the merge queue.
:check: alexcrichton merged PR #13487.
alexcrichton removed PR #13487 Move most module initialization to compiled code from the merge queue.
Last updated: Jun 01 2026 at 09:49 UTC