util: use indexed writes for inspected object properties

Avoid the cost of primordial push calls for each formatted property.

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
PR-URL: https://github.com/nodejs/node/pull/67297
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
Roberto Bianchi authored and GitHub committed 2026-11-13 17:11:04 +00:00
1 parent 925faf48f9
commit 02ad8f22f2
2 files changed
+11 -5

No files matched your search

+8
View File
@@ -14,6 +14,7 @@ const bench = common.createBenchmark(main, {
'Object',
'Object_empty',
'Object_deep_ln',
'Object_large',
'String',
'String_complex',
'String_boxed',
@@ -61,6 +62,13 @@ function main({ method, n, option }) {
g: 'seventh' } } } };
benchmark(n, obj, options || { depth: Infinity });
break;
case 'Object_large':
obj = {};
for (let i = 0; i < 50; i++) {
obj[`key${i}`] = i;
}
benchmark(n, obj, options);
break;
case 'String':
benchmark(n, 'Simple string', options);
break;
+3 -5
View File
@@ -1434,14 +1434,12 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
const tempValue = { [extraKeys[i]]: value.buffer[extraKeys[i]] };
formatted = formatExtraProperties(ctx, tempValue, recurseTimes, extraKeys[i], typedArray);
}
ArrayPrototypePush(output, formatted);
output[output.length] = formatted;
}
}
for (i = 0; i < keys.length; i++) {
ArrayPrototypePush(
output,
formatProperty(ctx, value, recurseTimes, keys[i], extrasType),
);
output[output.length] =
formatProperty(ctx, value, recurseTimes, keys[i], extrasType);
}
if (protoProps !== undefined) {
ArrayPrototypePushApply(output, protoProps);