Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
joyeecheung committed Apr 20, 2019
commit 8248be6a8e6606ffc7aeebc2fbec4cbcec98c8f6
8 changes: 7 additions & 1 deletion src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ using v8::Local;
using v8::Locker;
using v8::SealHandleScope;

const size_t NodeMainInstance::kNodeContextIndex = 0;

NodeMainInstance::NodeMainInstance(Isolate* isolate,
uv_loop_t* event_loop,
MultiIsolatePlatform* platform,
Expand Down Expand Up @@ -171,9 +173,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;
Comment thread
joyeecheung marked this conversation as resolved.
Outdated

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 @@ -105,6 +105,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