Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2021-12-26 22:28:51 +0300
committerNode.js GitHub Bot <github-bot@iojs.org>2022-01-01 21:36:50 +0300
commit69ea6775f456ce33032f3c1de01b07260679a88c (patch)
tree6edd64754fe6716dbb0e00dd1bf8ac4e733446b9 /src/env.cc
parent6932fb8bac3a4caf3f3fabee0a595a077f477f63 (diff)
src: store native async execution resources as `v8::Local`
This is possible because the async stack is always expected to match the native call stack, and saves performance overhead that comes from the usage of `v8::Global`. PR-URL: https://github.com/nodejs/node/pull/41331 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Darshan Sen <raisinten@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r--src/env.cc31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/env.cc b/src/env.cc
index bbc3f6a9a41..3f76c4bb770 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -1096,20 +1096,29 @@ void AsyncHooks::Deserialize(Local<Context> context) {
async_ids_stack_.Deserialize(context);
fields_.Deserialize(context);
async_id_fields_.Deserialize(context);
+
+ Local<Array> js_execution_async_resources;
if (info_->js_execution_async_resources != 0) {
- Local<Array> arr = context->GetDataFromSnapshotOnce<Array>(
- info_->js_execution_async_resources)
- .ToLocalChecked();
- js_execution_async_resources_.Reset(context->GetIsolate(), arr);
+ js_execution_async_resources =
+ context->GetDataFromSnapshotOnce<Array>(
+ info_->js_execution_async_resources).ToLocalChecked();
+ } else {
+ js_execution_async_resources = Array::New(context->GetIsolate());
}
+ js_execution_async_resources_.Reset(
+ context->GetIsolate(), js_execution_async_resources);
- native_execution_async_resources_.resize(
- info_->native_execution_async_resources.size());
+ // The native_execution_async_resources_ field requires v8::Local<> instances
+ // for async calls whose resources were on the stack as JS objects when they
+ // were entered. We cannot recreate this here; however, storing these values
+ // on the JS equivalent gives the same result, so we do that instead.
for (size_t i = 0; i < info_->native_execution_async_resources.size(); ++i) {
+ if (info_->native_execution_async_resources[i] == SIZE_MAX)
+ continue;
Local<Object> obj = context->GetDataFromSnapshotOnce<Object>(
info_->native_execution_async_resources[i])
.ToLocalChecked();
- native_execution_async_resources_[i].Reset(context->GetIsolate(), obj);
+ js_execution_async_resources->Set(context, i, obj).Check();
}
info_ = nullptr;
}
@@ -1155,9 +1164,11 @@ AsyncHooks::SerializeInfo AsyncHooks::Serialize(Local<Context> context,
info.native_execution_async_resources.resize(
native_execution_async_resources_.size());
for (size_t i = 0; i < native_execution_async_resources_.size(); i++) {
- info.native_execution_async_resources[i] = creator->AddData(
- context,
- native_execution_async_resources_[i].Get(context->GetIsolate()));
+ info.native_execution_async_resources[i] =
+ native_execution_async_resources_[i].IsEmpty() ? SIZE_MAX :
+ creator->AddData(
+ context,
+ native_execution_async_resources_[i]);
}
CHECK_EQ(contexts_.size(), 1);
CHECK_EQ(contexts_[0], env()->context());