Skip to content

Commit

Permalink
worker: use snapshot in workers spawned by workers
Browse files Browse the repository at this point in the history
Previously we didn't pass the snapshot data down to the isolate
data of workers so workers spawned by workers won't use the
snapshot. Fixes it by passing the snapshot data down.

PR-URL: #47731
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
joyeecheung authored and targos committed May 12, 2023
1 parent 1666a14 commit 6f3876c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ class WorkerThreadData {
isolate->SetStackLimit(w->stack_base_);

HandleScope handle_scope(isolate);
isolate_data_.reset(CreateIsolateData(isolate,
&loop_,
w_->platform_,
allocator.get()));
isolate_data_.reset(
CreateIsolateData(isolate,
&loop_,
w_->platform_,
allocator.get(),
w->snapshot_data()->AsEmbedderWrapper().get()));
CHECK(isolate_data_);
if (w_->per_isolate_opts_)
isolate_data_->set_options(std::move(w_->per_isolate_opts_));
Expand Down Expand Up @@ -315,6 +317,10 @@ void Worker::Run() {
// though.
TryCatch try_catch(isolate_);
if (snapshot_data_ != nullptr) {
Debug(this,
"Worker %llu uses context from snapshot %d\n",
thread_id_.id,
static_cast<int>(SnapshotData::kNodeBaseContextIndex));
context = Context::FromSnapshot(isolate_,
SnapshotData::kNodeBaseContextIndex)
.ToLocalChecked();
Expand All @@ -323,6 +329,8 @@ void Worker::Run() {
context = Local<Context>();
}
} else {
Debug(
this, "Worker %llu builds context from scratch\n", thread_id_.id);
context = NewContext(isolate_);
}
if (context.IsEmpty()) {
Expand Down

0 comments on commit 6f3876c

Please sign in to comment.