• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::GetEmbeddedSnapshotData`
26
27Then the `node_mksnapshot` executable is built with C++ files in this
28directory, as well as `src/node_snapshot_stub.cc` which defines the unresolved
29symbols.
30
31`node_mksnapshot` is run to generate a C++ file
32`<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc` that is similar to
33`src/node_snapshot_stub.cc` in structure, but contains the snapshot data
34written as static char array literals. Then `libnode` is built with
35`node_snapshot.cc` to produce the final Node.js executable with the snapshot
36data embedded.
37
38For debugging, Node.js can be built without Node.js's own snapshot if
39`--without-node-snapshot` is passed to `configure`. A Node.js executable
40with Node.js snapshot embedded can also be launched without deserializing
41from it if the command line argument `--no-node-snapshot` is passed.
42