docs/snapshot/architecture.md
To achieve fast startup times, V8 uses a Snapshot system. Instead of parsing and compiling the standard library and initializing the heap from scratch every time a new Isolate is created, V8 captures a snapshot of a fully initialized heap and persists it.
When a new Isolate starts up, it simply restores the heap state from the snapshot, which is significantly faster.
mksnapshotmksnapshot is a standalone executable tool built during the V8 build process.
The core logic for saving and restoring heap state is in the Serializer and Deserializer classes (in src/snapshot/).
SnapshotByteSink).
The snapshot data is not a raw memory dump. Instead, it is a stream of bytecode instructions that the Deserializer executes to reconstruct the heap. This design makes the snapshot format robust across different memory layouts and address spaces.
[!IMPORTANT] The serialization format is trusted and strictly build- and version-dependent. Code caches and snapshots include the V8 version and critical build flags as metadata. The deserializer will bail out and reject the snapshot if a mismatch is detected.
The bytecode is defined in src/snapshot/serializer-deserializer.h (in enum Bytecode) and includes instructions for:
kNewObject).kRootArrayConstants).kFixedRepeatRoot).By using a bytecode interpreter for deserialization, V8 can handle complex object graphs and cyclic references efficiently during isolate startup.
V8 uses several distinct snapshots to organize heap data:
undefined value, small integers, certain Maps).NativeContext.--shared-string-table).Independent of the startup snapshot, V8 also uses serialization for Code Caching.
BytecodeArray or optimized code and save it to disk. On subsequent loads, V8 can deserialize the code directly, bypassing parsing and compilation.CodeSerializer in src/snapshot/code-serializer.cc.V8 can compress the snapshot data to reduce the size of the binary or external snapshot files.
SnapshotCompression in src/snapshot/snapshot-compression.h & .cc.V8_SNAPSHOT_COMPRESSION build flag.src/snapshot/mksnapshot.cc: Entry point for the snapshot creation tool.src/snapshot/serializer.h & .cc: Base classes for serialization.src/snapshot/deserializer.h & .cc: Base classes for deserialization.src/snapshot/read-only-serializer.cc & read-only-deserializer.cc: Serializer and deserializer for the read-only space.src/snapshot/startup-serializer.cc & startup-deserializer.cc: Serializer and deserializer for the startup heap.src/snapshot/context-serializer.cc & context-deserializer.cc: Serializer and deserializer for contexts.src/snapshot/shared-heap-serializer.cc & shared-heap-deserializer.cc: Serializer and deserializer for the shared heap.src/snapshot/code-serializer.cc: Serializer for code caching.