Skip to content

sea: snapshot support in single executable applications

Refs: https://github.com/nodejs/single-executable/discussions/57

This patch adds snapshot support to single executable applications. To build a snapshot from the main script when preparing the blob that will be injected into the single executable application, add "useSnapshot": true to the configuration passed to --experimental-sea-config. For example:

{
    "main": "snapshot.js",
    "output": "sea-prep.blob",
    "useSnapshot": true
}

The main script used to build the snapshot must invoke v8.startupSnapshot.setDeserializeMainFunction() to configure the entry point. The generated startup snapshot would be part of the preparation blob and get injected into the final executable.

When the single executable application is launched, instead of running the main script from scratch, Node.js would instead deserialize the snapshot to get to the state initialized during build-time directly.

$ /path/to/node --experimental-sea-config sea-config.json
$ cp /path/to/node sea
$ postject sea NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
$ ./sea

Merge request reports

Loading