mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
src: elide heap allocation in structured clone implementation
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 (***)
PR-URL: https://github.com/nodejs/node/pull/61703
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
1 parent
6aa465c962
commit
0777dcccc7
1 file changed
+3
-3
@@ -1619,11 +1619,11 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Message> msg = std::make_shared<Message>();
|
||||
Message msg;
|
||||
Local<Value> result;
|
||||
if (msg->Serialize(env, context, value, transfer_list, Local<Object>())
|
||||
if (msg.Serialize(env, context, value, transfer_list, Local<Object>())
|
||||
.IsNothing() ||
|
||||
!msg->Deserialize(env, context, nullptr).ToLocal(&result)) {
|
||||
!msg.Deserialize(env, context, nullptr).ToLocal(&result)) {
|
||||
return;
|
||||
}
|
||||
args.GetReturnValue().Set(result);
|
||||
|
||||
Reference in new issue
Block a user