bootstrap: support configure-time user-land snapshot#42466
Closed
joyeecheung wants to merge 8 commits intonodejs:masterfrom
Closed
bootstrap: support configure-time user-land snapshot#42466joyeecheung wants to merge 8 commits intonodejs:masterfrom
joyeecheung wants to merge 8 commits intonodejs:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a less-ambitious version of #38905 which only supports user-land snapshot at configure time. I've made the last two commits separate in case they cause any regressions and it would be easier to revert them to test things out.
A quick example of the feature:
typescript.js: A modified version of https://github.com/microsoft/TypeScript/blob/main/lib/typescript.js which stores the initialized ts namespace in globalThis, see #38905For now the user can initialize the data/apps to be snapshotted in the entry point specified by
--node-snapshot-mainand hang this somewhere they can retrieve back after the snapshot is deserialized e.g. globalThis, we can invent better APIs in subsequent PRs (e.g. allowing the user to add a module into the module graph at build time that can berequireed back at runtime). Similar to #38905 the user has to bundle their app into one script to be built into the binary, as user-land modules are not yet supported (we'll need to do more refactoring like #42191 to support user modules in the snapshot).bootstrap: refresh options in pre-execution
Refresh the options map during pre-execution to pave the way for
user land snapshots which may need to access run-time options at
snapshot-building time. The default embedded bootstrap snapshot
is still prevented from accessing them at snapshot building time
since it serves a wider audience and is ignorant of application
states, while the user-land snapshots are meant to be
application-specific and so it makes sense for them to access
runtime states as long as the snapshotted-code
works with re-initialized runtime states.
build: add --node-snapshot-main configure option
This adds a --build-snapshot runtime option which is currently only
supported by the node_mksnapshot binary, and a --node-snapshot-main
configure option that makes use it to run a custom script when
building the embedded snapshot. The idea is to have this experimental
feature in core as a configure-time feature for now, and investigate
the renaming V8 bugs before we make it available to more users via
making it a runtime option.
bootstrap: make I/O streams work with user-land snapshot
Use the mksnapshot cleanup hooks to release the references
to the native streams so that they can be destroyed right
before the snapshot is taken, and move the initialization
of the global console to pre-execution so that they can be
re-initialized during snapshot dehydration. This makes
it possible for user-land snapshots to use the I/O during
snapshot building.
bootstrap: run inspector and event loop in snapshot builder
This makes --inspect and stdin/out functional in the embedded snapshot,
currently it's not guaranteed that these work perfectly, the
plan is to investigate any out-of-sync states that might appear
in user land snapshots with this while the it is a configure-time
feature.
Refs: #35711