Stream: general

Topic: Snapshot for WasmGC in wasmtime


view this post on Zulip Dmitry Bezhetskov (Nov 06 2026 at 14:28):

Hey! Since quite a few new language runtimes are targeting WasmGC, I think it would be great to have something similar to Wizer, but with support for GC types.

This would require support from the host runtime, so I think Wasmtime would be a perfect fit.
I imagine the design could follow V8's snapshot mechanism: serializing the GC heap while allowing embedders to provide custom callbacks for serializing and deserializing host-managed state.

Does anything like this already exist in Wasmtime?
If not, would you be interested in adding it?

view this post on Zulip Till Schneidereit (Nov 06 2026 at 19:14):

it doesn't yet exist, but we've talked about it. Wasmtime's implementation of WasmGC would lend itself very well to it, too, since the GC heap is itself a linear memory. On whether we'd be interested in adding it: in principle yes! In practice, I think it depends a bit on how much review and then ongoing maintenance effort it'd be, and what the security implications would be. @fitzgen (he/him) would be able to say more

view this post on Zulip fitzgen (he/him) (Nov 06 2026 at 20:55):

it is possible, but the other thing to keep track of is the collector's outside-the-heap state. this could potentially be marked #[derive(Clone, serde::Serialize, serde::Deserialize)] and plumbed through the GcHeap trait methods but it might not be exactly what we'd actually want to do. But the snapshots would be tied to a specific version of Wasmtime, and could break even across patch versions. and ofc they would not be engine independent anymore, like Wizer snapshots. with enough special reflection APIs in the engine you could encode the snapshot as core Wasm and just have code to rebuild the heap graph on demand, which gives the portability back, but costs initialization performance.

I was actually just talking with @Chris Fallin about this kind of thing yesterday, but in the context of record/replay and time travel debugging, where there are slightly different constraints (perf is important but perhaps not quite to the same degree, portability across engines is highly desirable for the recording but a snapshot never actually needs to persist across a single process, etc...)

But backing up, while I don't think anything here is impossible with enough effort, I don't believe this is something that we have bandwidth to review+maintain from a contributor who is not a core maintainer.

view this post on Zulip Chris Fallin (Nov 06 2026 at 21:04):

It seems likely to me that "snapshot back to initialization expressions / a synthesized init function that ties the knot on any cycles" is the better answer to produce a portable Wasm that contains the GC snapshot. That then composes with our wasm -> cwasm AOT compilation step to potentially give a GC heap snapshot (tied to a specific Wasmtime version because the whole cwasm is) that can provide a CoW backing for fast instantiation. In other words, Wasm spec-level description goes with Wasm, byte-level description goes with cwasm-for-this-Wasmtime-version.

(I recall early discussion here on Zulip somewhere about exactly the above re: const-expression GC ops + code to tie the knot; can't find it at the moment)

view this post on Zulip Till Schneidereit (Nov 10 2026 at 16:33):

where that approach is viable, I agree. I had a use case where doing just that brought startup time from 750ms or so to something like 250ms, so still much worse than a wizer-style snapshot

view this post on Zulip fitzgen (he/him) (Nov 10 2026 at 17:03):

Chris Fallin said:

(tied to a specific Wasmtime version because the whole cwasm is)

Note that we do have to preserve .cwasm compat across patch releases, which could become difficult if we serialized implementation-specific GC state into .cwasms. specifically I am thinking of the state outside the heap itself again, e.g. a serialized free list or whatever. it means that if we have a vulnerability whose fix requires changing the free list representation or something we are screwed.

view this post on Zulip Chris Fallin (Nov 10 2026 at 17:05):

we do have to preserve .cwasm compat across patch releases

ah interesting! I actually wasn't aware that this was one of our guarantees...

view this post on Zulip Chris Fallin (Nov 10 2026 at 17:05):

(at least, this hasn't come up before when e.g. changing libcalls -- this would mean we basically can only change libcalls at a major version release)

view this post on Zulip fitzgen (he/him) (Nov 10 2026 at 17:08):

yeah, so that people don't need to recompile every guest when shipping a wasmtime security patch

view this post on Zulip bjorn3 (Nov 11 2026 at 10:44):

You still have to recompile every guest whenever there is a fixed miscompilation, right?

view this post on Zulip bjorn3 (Nov 11 2026 at 10:46):

Chris Fallin said:

(at least, this hasn't come up before when e.g. changing libcalls -- this would mean we basically can only change libcalls at a major version release)

Or if only forward compat is required for .cwasm files, you could add new libcalls in patch releases, but not change or remove existing ones.

view this post on Zulip Chris Fallin (Nov 11 2026 at 16:32):

Digging a bit more because this is a surprise to me (I recall waiting for world-recompiles with security patch deployments, and also Pat adding ModuleVersionStrategy so we can explicitly reason about this, in #3271, and also a number of discussions in the past where we explicitly say that cwasms are an internal implementation detail and not stable). It seems our default version-strategy is indeed only the major version number.

It might be interesting to talk about this more, both with input from folks who deploy "large worlds" these days, and from a maintenance + feature flexibility perspective. It seems like it would be a nice capability generally to implement the above functionality, where we can mmap a GC heap snapshot at startup -- otherwise we deny the same microsecond-instantiation advantages to a future GC-guest world that we have today for linear memories. And it also seems like a potential problem if we need a semver break on a libcall or any VM data structure layout (or a change to any logic embedded in any inline compiled sequence -- e.g., any GC barrier or operation) to fix a security issue. Curious what others think...

view this post on Zulip Chris Fallin (Nov 11 2026 at 16:33):

(I'm disappearing for the week but maybe next week's wasmtime meeting would be good to discuss)


Last updated: Nov 19 2026 at 20:05 UTC