Skip to content

Commit 3bca5c2

Browse files
authored
worker: use snapshot in workers spawned by workers
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]>
1 parent 2ad5ea6 commit 3bca5c2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/node_worker.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,12 @@ class WorkerThreadData {
179179
isolate->SetStackLimit(w->stack_base_);
180180

181181
HandleScope handle_scope(isolate);
182-
isolate_data_.reset(CreateIsolateData(isolate,
183-
&loop_,
184-
w_->platform_,
185-
allocator.get()));
182+
isolate_data_.reset(
183+
CreateIsolateData(isolate,
184+
&loop_,
185+
w_->platform_,
186+
allocator.get(),
187+
w->snapshot_data()->AsEmbedderWrapper().get()));
186188
CHECK(isolate_data_);
187189
if (w_->per_isolate_opts_)
188190
isolate_data_->set_options(std::move(w_->per_isolate_opts_));
@@ -315,6 +317,10 @@ void Worker::Run() {
315317
// though.
316318
TryCatch try_catch(isolate_);
317319
if (snapshot_data_ != nullptr) {
320+
Debug(this,
321+
"Worker %llu uses context from snapshot %d\n",
322+
thread_id_.id,
323+
static_cast<int>(SnapshotData::kNodeBaseContextIndex));
318324
context = Context::FromSnapshot(isolate_,
319325
SnapshotData::kNodeBaseContextIndex)
320326
.ToLocalChecked();
@@ -323,6 +329,8 @@ void Worker::Run() {
323329
context = Local<Context>();
324330
}
325331
} else {
332+
Debug(
333+
this, "Worker %llu builds context from scratch\n", thread_id_.id);
326334
context = NewContext(isolate_);
327335
}
328336
if (context.IsEmpty()) {

0 commit comments

Comments
 (0)