From c01d966404719f175758e9bcd29f62cdf143d526 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 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index 7f5d9b9e1821..e861e499534c 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -1571,17 +1571,17 @@ 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 // internal version of them. - LocalVector parameters( - isolate, - { - FIXED_ONE_BYTE_STRING(isolate, "require"), - FIXED_ONE_BYTE_STRING(isolate, "__filename"), - FIXED_ONE_BYTE_STRING(isolate, "__dirname"), - }); + LocalVector parameters(isolate, + { + env->require_string(), + env->__filename_string(), + env->__dirname_string(), + }); ScriptOrigin script_origin(filename, 0, 0, true); ScriptCompiler::Source script_source(source, script_origin);