Stream: git-wasmtime

Topic: wasmtime / PR #13487 Move most module initialization to c...


view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 21:47):

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 of FuncKey corresponding 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 say needs_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).

view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 21:48):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 21:48):

: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.

view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 22:13):

alexcrichton updated PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 22:13):

alexcrichton has marked PR #13487 as ready for review.

view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 22:13):

alexcrichton requested cfallin for a review on PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 22:13):

alexcrichton requested wasmtime-compiler-reviewers for a review on PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 22:13):

alexcrichton requested wasmtime-core-reviewers for a review on PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 22:25):

alexcrichton updated PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 26 2026 at 23:28):

alexcrichton updated PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 27 2026 at 04:03):

github-actions[bot] added the label wasmtime:api on PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 27 2026 at 04:03):

github-actions[bot] added the label wasmtime:ref-types on PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 27 2026 at 04:03):

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:

To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.

Learn more.
</details>

view this post on Zulip Wasmtime GitHub notifications bot (May 27 2026 at 21:12):

:thumbs_up: cfallin submitted PR review:

This looks largely good to me -- nice simplification! Some thoughts below but no blockers at all.

view this post on Zulip Wasmtime GitHub notifications bot (May 27 2026 at 21:12):

:speech_balloon: cfallin created PR review comment:

s/t o/to/ ?

view this post on Zulip Wasmtime GitHub notifications bot (May 27 2026 at 21:12):

: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> for Op and 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.

view this post on Zulip Wasmtime GitHub notifications bot (May 27 2026 at 21:12):

:speech_balloon: cfallin created PR review comment:

s/think/thin/ ?

view this post on Zulip Wasmtime GitHub notifications bot (May 27 2026 at 21:12):

:speech_balloon: cfallin created PR review comment:

Would it make sense to sort global_initializers by def_index and 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...

view this post on Zulip Wasmtime GitHub notifications bot (May 27 2026 at 22:03):

:thumbs_up: fitzgen submitted PR review:

Nothing to add on top of Chris's comments.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 01:21):

alexcrichton updated PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 01:22):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 01:22):

:speech_balloon: alexcrichton created PR review comment:

Good point! It's already amortized a bit where I think make_global happens at most once-per-global-per-function, but the array is also already sorted so I added a binary search.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 01:25):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 01:25):

: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)

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 01:25):

alexcrichton has enabled auto merge for PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 01:32):

alexcrichton added PR #13487 Move most module initialization to compiled code to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 01:56):

github-merge-queue[bot] removed PR #13487 Move most module initialization to compiled code from the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 02:05):

alexcrichton added PR #13487 Move most module initialization to compiled code to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 02:29):

:check: alexcrichton merged PR #13487.

view this post on Zulip Wasmtime GitHub notifications bot (May 28 2026 at 02:29):

alexcrichton removed PR #13487 Move most module initialization to compiled code from the merge queue.


Last updated: Jun 01 2026 at 09:49 UTC