Skip to content

Commit

Permalink
src: enable context snapshot after running per-context scripts
Browse files Browse the repository at this point in the history
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.

PR-URL: #27321
Refs: #17058
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
joyeecheung authored and targos committed Apr 27, 2019
1 parent 45d6106 commit 228127f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,13 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment(
isolate_->GetHeapProfiler()->StartTrackingHeapObjects(true);
}

Local<Context> context = NewContext(isolate_);
Local<Context> context;
if (deserialize_mode_) {
context =
Context::FromSnapshot(isolate_, kNodeContextIndex).ToLocalChecked();
SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers);
} else {
context = NewContext(isolate_);
}

CHECK(!context.IsEmpty());
Expand Down
2 changes: 2 additions & 0 deletions src/node_main_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class NodeMainInstance {
static const IndexArray* GetIsolateDataIndexes();
static v8::StartupData* GetEmbeddedSnapshotBlob();

static const size_t kNodeContextIndex = 0;

private:
NodeMainInstance(const NodeMainInstance&) = delete;
NodeMainInstance& operator=(const NodeMainInstance&) = delete;
Expand Down
3 changes: 3 additions & 0 deletions tools/snapshot/snapshot_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ std::string SnapshotBuilder::Generate(
HandleScope scope(isolate);
creator.SetDefaultContext(Context::New(isolate));
isolate_data_indexes = main_instance->isolate_data()->Serialize(&creator);

size_t index = creator.AddContext(NewContext(isolate));
CHECK_EQ(index, NodeMainInstance::kNodeContextIndex);
}

// Must be out of HandleScope
Expand Down

0 comments on commit 228127f

Please sign in to comment.