Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 387e292

Browse filesBrowse files
authored
src: generate default snapshot with --predictable
To improve determinism of snapshot generation, add --predictable to the V8 flags used to initialize a process launched to generate snapshot. Also add a kGeneratePredictableSnapshot flag to ProcessInitializationFlags for this and moves the configuration of these flags into node::InitializeOncePerProcess() so that it can be shared by embedders. PR-URL: #48749 Refs: nodejs/build#3043 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 81e4d2e commit 387e292
Copy full SHA for 387e292

File tree

Expand file treeCollapse file tree

3 files changed

+10
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+10
-3
lines changed
Open diff view settings
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,12 @@ static ExitCode InitializeNodeWithArgsInternal(
838838
V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1);
839839
#endif
840840

841+
if (!!(flags & ProcessInitializationFlags::kGeneratePredictableSnapshot) ||
842+
per_process::cli_options->per_isolate->build_snapshot) {
843+
v8::V8::SetFlagsFromString("--predictable");
844+
v8::V8::SetFlagsFromString("--random_seed=42");
845+
}
846+
841847
// Specify this explicitly to avoid being affected by V8 changes to the
842848
// default value.
843849
V8::SetFlagsFromString("--rehash-snapshot");
Collapse file

‎src/node.h‎

Copy file name to clipboardExpand all lines: src/node.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ enum Flags : uint32_t {
265265
// cppgc::InitializeProcess() before creating a Node.js environment
266266
// and call cppgc::ShutdownProcess() before process shutdown.
267267
kNoInitializeCppgc = 1 << 13,
268+
// Initialize the process for predictable snapshot generation.
269+
kGeneratePredictableSnapshot = 1 << 14,
268270

269271
// Emulate the behavior of InitializeNodeWithArgs() when passing
270272
// a flags argument to the InitializeOncePerProcess() replacement
Collapse file

‎tools/snapshot/node_mksnapshot.cc‎

Copy file name to clipboardExpand all lines: tools/snapshot/node_mksnapshot.cc
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ int main(int argc, char* argv[]) {
5050
setvbuf(stderr, nullptr, _IONBF, 0);
5151
#endif // _WIN32
5252

53-
v8::V8::SetFlagsFromString("--random_seed=42");
54-
v8::V8::SetFlagsFromString("--harmony-import-assertions");
5553
return BuildSnapshot(argc, argv);
5654
}
5755

@@ -65,7 +63,8 @@ int BuildSnapshot(int argc, char* argv[]) {
6563

6664
std::unique_ptr<node::InitializationResult> result =
6765
node::InitializeOncePerProcess(
68-
std::vector<std::string>(argv, argv + argc));
66+
std::vector<std::string>(argv, argv + argc),
67+
node::ProcessInitializationFlags::kGeneratePredictableSnapshot);
6968

7069
CHECK(!result->early_return());
7170
CHECK_EQ(result->exit_code(), 0);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.