internals · 5 of 6 · snapshots

Snapshots

QuickJS can serialize objects and bytecode, but not Rust callbacks, template metadata, or embedder slots. Those are exactly what a deno_core snapshot needs, so a v8x snapshot is one serialized global graph plus a replay log for the native side.

the QuickJS object graph and a HOSTDATA replay log both feed one snapshot container; restore runs a five-step timeline: disable GC, decode graph, replay HOSTDATA, reconnect slots, enable GC, with GC disabled through the middle
recordcontents
context recordthe global object graph, serialized as one graph so repeated references keep their identity; template descriptions; lexical globals; embedder and context slots; a bitmap of values already rooted in the graph
host functiona HOSTDATA entry holding the function’s index in the rusty_v8 external-reference table

Restore order matters:

  1. create a fresh context
  2. disable GC
  3. read the global graph
  4. rebuild template metadata and reconnect module exports
  5. restore lexical bindings and embedder slots
  6. re-enable GC with a threshold of at least 1.5 times the live size

GC stays off for the window in which JavaScript graph edges exist but the native metadata is still disconnected. A collection there would sweep objects the replay log is about to wire up.

System JSC exposes neither heap snapshots nor a bytecode-cache API, so snapshot creation is unavailable on that backend.

Next: WebAssembly: WAMR behind V8′s Wasm API