From 3bca5c2eb8cfa779c5899351750c57306644f0c2 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 4 May 2023 14:54:25 +0200 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/47731 Reviewed-By: Yagiz Nizipli Reviewed-By: Anna Henningsen Reviewed-By: Benjamin Gruenbaum Reviewed-By: Chengzhong Wu --- src/node_worker.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/node_worker.cc b/src/node_worker.cc index 7be78dcdb93d1d..2bb5bdf569ebef 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -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_)); @@ -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(SnapshotData::kNodeBaseContextIndex)); context = Context::FromSnapshot(isolate_, SnapshotData::kNodeBaseContextIndex) .ToLocalChecked(); @@ -323,6 +329,8 @@ void Worker::Run() { context = Local(); } } else { + Debug( + this, "Worker %llu builds context from scratch\n", thread_id_.id); context = NewContext(isolate_); } if (context.IsEmpty()) {