• Home
Name
Date
Size
#Lines
LOC

..--

README.mdD12-May-20241.9 KiB4333

node_mksnapshot.ccD12-May-20241.1 KiB5544

snapshot_builder.ccD12-May-20243.1 KiB10985

snapshot_builder.hD12-May-2024385 1612

README.md

1# Node.js startup snapshot builder
2
3This is the V8 startup snapshot builder of Node.js. Not to be confused with
4V8's own snapshot builder, which builds a snapshot containing JavaScript
5builtins, this builds a snapshot containing Node.js builtins that can be
6deserialized on top of V8's own startup snapshot. When Node.js is launched,
7instead of executing code to bootstrap, it can deserialize the context from
8an embedded snapshot, which readily contains the result of the bootstrap, so
9that Node.js can start up faster.
10
11Currently only the main context of the main Node.js instance supports snapshot
12deserialization, and the snapshot does not yet cover the entire bootstrap
13process. Work is being done to expand the support.
14
15## How it's built and used
16
17The snapshot builder is built with the `node_mksnapshot` target in `node.gyp`
18when `node_use_node_snapshot` is set to true, which is currently done by
19default.
20
21In the default build of the Node.js executable, to embed a V8 startup snapshot
22into the Node.js executable, `libnode` is first built with these unresolved
23symbols:
24
25- `node::NodeMainInstance::GetEmbeddedSnapshotBlob`
26- `node::NodeMainInstance::GetIsolateDataIndexes`
27
28Then the `node_mksnapshot` executable is built with C++ files in this
29directory, as well as `src/node_snapshot_stub.cc` which defines the unresolved
30symbols.
31
32`node_mksnapshot` is run to generate a C++ file
33`<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc` that is similar to
34`src/node_snapshot_stub.cc` in structure, but contains the snapshot data
35written as static char array literals. Then `libnode` is built with
36`node_snapshot.cc` to produce the final Node.js executable with the snapshot
37data embedded.
38
39For debugging, Node.js can be built without Node.js's own snapshot if
40`--without-node-snapshot` is passed to `configure`. A Node.js executable
41with Node.js snapshot embedded can also be launched without deserializing
42from it if the command line argument `--no-node-snapshot` is passed.
43