From fe4be5887bb88f7f171dd5eaa86d5c95f989c9fc Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Thu, 15 Jan 2026 00:11:06 +0300 Subject: [PATCH 1/2] fs: cache context lookup in vectored io loops --- src/node_file.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index 15e0ff923bc112..1a1406c1144b43 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2391,9 +2391,10 @@ static void WriteBuffers(const FunctionCallbackInfo& args) { MaybeStackBuffer iovs(chunks->Length()); + Local context = env->context(); for (uint32_t i = 0; i < iovs.length(); i++) { Local chunk; - if (!chunks->Get(env->context(), i).ToLocal(&chunk)) return; + if (!chunks->Get(context, i).ToLocal(&chunk)) return; CHECK(Buffer::HasInstance(chunk)); iovs[i] = uv_buf_init(Buffer::Data(chunk), Buffer::Length(chunk)); } @@ -2776,9 +2777,10 @@ static void ReadBuffers(const FunctionCallbackInfo& args) { MaybeStackBuffer iovs(buffers->Length()); // Init uv buffers from ArrayBufferViews + Local context = env->context(); for (uint32_t i = 0; i < iovs.length(); i++) { Local buffer; - if (!buffers->Get(env->context(), i).ToLocal(&buffer)) return; + if (!buffers->Get(context, i).ToLocal(&buffer)) return; CHECK(Buffer::HasInstance(buffer)); iovs[i] = uv_buf_init(Buffer::Data(buffer), Buffer::Length(buffer)); } From 77c67fd6bd340c1f91379a7ab519829581bf6716 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Thu, 15 Jan 2026 22:17:55 +0300 Subject: [PATCH 2/2] update context usage in WriteBuffers and ReadBuffers functions --- src/node_file.cc | 6 ++---- src/node_realm-inl.h | 5 +++++ src/node_realm.cc | 4 ---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index 1a1406c1144b43..15e0ff923bc112 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2391,10 +2391,9 @@ static void WriteBuffers(const FunctionCallbackInfo& args) { MaybeStackBuffer iovs(chunks->Length()); - Local context = env->context(); for (uint32_t i = 0; i < iovs.length(); i++) { Local chunk; - if (!chunks->Get(context, i).ToLocal(&chunk)) return; + if (!chunks->Get(env->context(), i).ToLocal(&chunk)) return; CHECK(Buffer::HasInstance(chunk)); iovs[i] = uv_buf_init(Buffer::Data(chunk), Buffer::Length(chunk)); } @@ -2777,10 +2776,9 @@ static void ReadBuffers(const FunctionCallbackInfo& args) { MaybeStackBuffer iovs(buffers->Length()); // Init uv buffers from ArrayBufferViews - Local context = env->context(); for (uint32_t i = 0; i < iovs.length(); i++) { Local buffer; - if (!buffers->Get(context, i).ToLocal(&buffer)) return; + if (!buffers->Get(env->context(), i).ToLocal(&buffer)) return; CHECK(Buffer::HasInstance(buffer)); iovs[i] = uv_buf_init(Buffer::Data(buffer), Buffer::Length(buffer)); } diff --git a/src/node_realm-inl.h b/src/node_realm-inl.h index 9d0510f42d5c0c..b004bd1e150020 100644 --- a/src/node_realm-inl.h +++ b/src/node_realm-inl.h @@ -5,6 +5,7 @@ #include "node_context_data.h" #include "node_realm.h" +#include "util-inl.h" namespace node { @@ -46,6 +47,10 @@ inline v8::Isolate* Realm::isolate() const { return isolate_; } +inline v8::Local Realm::context() const { + return PersistentToLocal::Strong(context_); +} + inline Realm::Kind Realm::kind() const { return kind_; } diff --git a/src/node_realm.cc b/src/node_realm.cc index 3674235a4e34da..d2459d4eeb3373 100644 --- a/src/node_realm.cc +++ b/src/node_realm.cc @@ -295,10 +295,6 @@ void Realm::VerifyNoStrongBaseObjects() { }); } -v8::Local Realm::context() const { - return PersistentToLocal::Strong(context_); -} - // Per-realm strong value accessors. The per-realm values should avoid being // accessed across realms. #define V(PropertyName, TypeName) \