From 8846c7a152262525027053b34026446e678817c3 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 6 Feb 2026 14:48:56 +0800 Subject: [PATCH] src: elide heap allocation in structured clone implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Small perf improvement: $ node benchmark/compare.js --runs 100 \ > --old ./node-0da120f879 --new ./node \ > --filter structured-clone misc > comparison.csv && \ > npx node-benchmark-compare comparison.csv [00:02:15|% 100| 1/1 files | 200/200 runs | 3/3 configs]: Done confidence improvement accuracy (*) (**) (***) misc/structured-clone.js n=10000 type='arraybuffer' ** 1.81 % ±1.28% ±1.68% ±2.16% misc/structured-clone.js n=10000 type='object' * 0.62 % ±0.55% ±0.73% ±0.93% misc/structured-clone.js n=10000 type='string' *** 8.30 % ±1.46% ±1.92% ±2.47% Be aware that when doing many comparisons the risk of a false-positive result increases. In this case, there are 3 comparisons, you can thus expect the following amount of false-positive results: 0.15 false positives, when considering a 5% risk acceptance (*, **, ***), 0.03 false positives, when considering a 1% risk acceptance (**, ***), 0.00 false positives, when considering a 0.1% risk acceptance (***) --- src/node_messaging.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 8c51ae4e0a4359..76c934ccbc9873 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -1619,11 +1619,11 @@ static void StructuredClone(const FunctionCallbackInfo& args) { } } - std::shared_ptr msg = std::make_shared(); + Message msg; Local result; - if (msg->Serialize(env, context, value, transfer_list, Local()) + if (msg.Serialize(env, context, value, transfer_list, Local()) .IsNothing() || - !msg->Deserialize(env, context, nullptr).ToLocal(&result)) { + !msg.Deserialize(env, context, nullptr).ToLocal(&result)) { return; } args.GetReturnValue().Set(result);