src: implement minimal v8 snapshot integration
This PR adds minimal support for embedded v8 snapshot. The generated snapshot currently includes:
- Per-isolate data (symbols and strings)
- The main context snapshotted after running the per-context scripts
At the moment, we do not create any external reference at the point when the snapshot is captured. To snapshot more of the bootstrap result, we'll need to implement external reference bookkeeping in a future PR. In this PR the setup of the error handlers is delayed until after the context is created, because attaching the error message handler creates an external reference to the C++ function.
This means any errors thrown during the snapshot generation will be handled by the default
handler and won't have the fancy error stack traces generated by node:: PrintException
,
but that should be rare and should only happen during local development (it was broken until
https://github.com/nodejs/node/pull/27236 anyway).
src: allow creating NodeMainInstance that does not own the isolate
Allows instantiating a NodeMainInstance with an isolate whose initialization and disposal are controlled by the caller.
src: implement IsolateData serialization and deserialization
This patch allows serializing per-isolate data into an isolate snapshot and deserializing them from an isolate snapshot.
tools: implement node_mksnapshot
Implements a node_mksnapshot target that generates a snapshot blob from a Node.js main instance's isolate, and serializes the data blob with other additional data into a C++ file that can be embedded into the Node.js binary.
src: enable snapshot with per-isolate data
Enable serializing the isolate from an isolate snapshot generated by node_mksnapshot with per-isolate data.
src: enable context snapshot after running per-context scripts
At build time, snapshot the context after running per-context scripts in the main instance, and in the final build, deserialize the context in the main instance.
This provides a ~5% in the misc/startup benchmark when the instance is launched within a process that runs test/fixtures/semicolon.js.
Refs: https://github.com/nodejs/node/issues/17058
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
commit message follows commit guidelines