镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 531d4aa

Browse files
committed
bench(json): isolate replacer membership cost (#519)
Add a 16,384-key empty-object row that forces complete JSON.stringify PropertyList construction while excluding large-object shape creation, property lookup, and member serialization. Retain the existing total-pipeline row as a separate end-to-end signal. The production ReleaseFast parent records a 173.4 ms invocation and checksum 16,404. The checksum covers output, replacer length, and boundary key lengths; semantic tests separately enforce getter/coercion and first-occurrence behavior. Benchmark-only change: flips 0 test262 cases.
1 parent 95ef010 commit 531d4aa

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎bench/representative_comparison.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ function representativeJsonStringifyReplacer(jobs, lane) {
135135
return total;
136136
}
137137

138+
// Isolate PropertyList membership from object construction/property lookup.
139+
// JSON.stringify must still consume and deduplicate the complete replacer even
140+
// when the serialized object has no matching properties.
141+
function representativeJsonStringifyReplacerMembership(jobs, lane) {
142+
var width = 16384;
143+
var replacer = [];
144+
for (var i = 0; i < width; i = i + 1)
145+
replacer.push("field-" + ((i * 17 + lane) & (width - 1)));
146+
var total = 0;
147+
for (var job = 0; job < jobs; job = job + 1) {
148+
var encoded = JSON.stringify({}, replacer);
149+
total = total + encoded.length + replacer.length +
150+
replacer[0].length + replacer[replacer.length - 1].length;
151+
}
152+
return total;
153+
}
154+
138155
function representativeCollections(jobs, lane, variant) {
139156
var total = 0;
140157
for (var job = 0; job < jobs; job = job + 1) {
@@ -485,6 +502,7 @@ function benchmarkFunction(name) {
485502
if (name === "representative_json_reviver_source") return representativeJsonReviverSource;
486503
if (name === "representative_json_escaped_strings") return representativeJsonEscapedStrings;
487504
if (name === "representative_json_stringify_replacer") return representativeJsonStringifyReplacer;
505+
if (name === "representative_json_stringify_replacer_membership") return representativeJsonStringifyReplacerMembership;
488506
if (name === "representative_collections") return function (jobs, lane) { return representativeCollections(jobs, lane, 0); };
489507
if (name === "representative_collections_variant") return function (jobs, lane) { return representativeCollections(jobs, lane, 1); };
490508
if (name === "representative_strong_identity_collections") return function (jobs, lane) { return representativeStrongIdentityCollections(jobs, lane, 0); };

0 commit comments

Comments
 (0)