From d17be3171d6303a5d0ba545bddde92008cdac08e Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sat, 27 May 2023 16:03:25 +0530 Subject: [PATCH] sea: pass code cache data as an external buffer to JS Otherwise, we were unnecessarily creating an additional copy. Signed-off-by: Darshan Sen --- src/node_sea.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/node_sea.cc b/src/node_sea.cc index a99055075de614..0bdd87e8424bbf 100644 --- a/src/node_sea.cc +++ b/src/node_sea.cc @@ -191,12 +191,19 @@ void GetCodeCache(const FunctionCallbackInfo& args) { SeaResource sea_resource = FindSingleExecutableResource(); - Local buf = - Buffer::Copy( - env, - reinterpret_cast(sea_resource.code_cache.data()), - sea_resource.code_cache.length()) - .ToLocalChecked(); + Local buf; + if (!Buffer::New( + env, + const_cast(sea_resource.code_cache.data()), + sea_resource.code_cache.length(), + [](char* /* data */, void* /* hint */) { + // We don't free the code cache data string because it is not owned + // by us. + }, + nullptr) + .ToLocal(&buf)) { + return; + } args.GetReturnValue().Set(buf); }