From 97f69feda55d79bdab421dd3727671239a024d16 Mon Sep 17 00:00:00 2001 From: agape1225 <49804691+agape1225@users.noreply.github.com> Date: Fri, 21 Aug 2026 21:04:50 +0900 Subject: [PATCH] src: reuse cached strings in CompileSerializeMain CompileSerializeMain() created new "require", "__filename", and "__dirname" strings via FIXED_ONE_BYTE_STRING() on every call, even though these strings are already cached on IsolateData/Environment as require_string(), __filename_string(), and __dirname_string() (defined via PER_ISOLATE_STRING_PROPERTIES in src/env_properties.h) and are reused this way elsewhere (e.g. the sibling RunEmbedderPreload() already obtains Environment* the same way). Signed-off-by: agape1225 <49804691+agape1225@users.noreply.github.com> --- src/node_snapshotable.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index 7f5d9b9e1821..e082dcae82c6 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -1571,6 +1571,7 @@ void CompileSerializeMain(const FunctionCallbackInfo& args) { CHECK(args[0]->IsString()); Local filename = args[0].As(); Local source = args[1].As(); + Environment* env = Environment::GetCurrent(args); Isolate* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); // TODO(joyeecheung): do we need all of these? Maybe we would want a less @@ -1578,9 +1579,9 @@ void CompileSerializeMain(const FunctionCallbackInfo& args) { LocalVector parameters( isolate, { - FIXED_ONE_BYTE_STRING(isolate, "require"), - FIXED_ONE_BYTE_STRING(isolate, "__filename"), - FIXED_ONE_BYTE_STRING(isolate, "__dirname"), + env->require_string(), + env->__filename_string(), + env->__dirname_string(), }); ScriptOrigin script_origin(filename, 0, 0, true);