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. PR-URL: https://github.com/nodejs/node/pull/27321 Refs: https://github.com/nodejs/node/issues/17058 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
bf5dadeef0
commit
eb23b176d8
@ -171,9 +171,13 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment(
|
|||||||
isolate_->GetHeapProfiler()->StartTrackingHeapObjects(true);
|
isolate_->GetHeapProfiler()->StartTrackingHeapObjects(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Local<Context> context = NewContext(isolate_);
|
Local<Context> context;
|
||||||
if (deserialize_mode_) {
|
if (deserialize_mode_) {
|
||||||
|
context =
|
||||||
|
Context::FromSnapshot(isolate_, kNodeContextIndex).ToLocalChecked();
|
||||||
SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers);
|
SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers);
|
||||||
|
} else {
|
||||||
|
context = NewContext(isolate_);
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(!context.IsEmpty());
|
CHECK(!context.IsEmpty());
|
||||||
|
@ -75,6 +75,8 @@ class NodeMainInstance {
|
|||||||
static const IndexArray* GetIsolateDataIndexes();
|
static const IndexArray* GetIsolateDataIndexes();
|
||||||
static v8::StartupData* GetEmbeddedSnapshotBlob();
|
static v8::StartupData* GetEmbeddedSnapshotBlob();
|
||||||
|
|
||||||
|
static const size_t kNodeContextIndex = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NodeMainInstance(const NodeMainInstance&) = delete;
|
NodeMainInstance(const NodeMainInstance&) = delete;
|
||||||
NodeMainInstance& operator=(const NodeMainInstance&) = delete;
|
NodeMainInstance& operator=(const NodeMainInstance&) = delete;
|
||||||
|
@ -104,6 +104,9 @@ std::string SnapshotBuilder::Generate(
|
|||||||
HandleScope scope(isolate);
|
HandleScope scope(isolate);
|
||||||
creator.SetDefaultContext(Context::New(isolate));
|
creator.SetDefaultContext(Context::New(isolate));
|
||||||
isolate_data_indexes = main_instance->isolate_data()->Serialize(&creator);
|
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
|
// Must be out of HandleScope
|
||||||
|
Loading…
x
Reference in New Issue
Block a user