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

Commit 4be2bc6

Browse files
committed
bench(json): add stringify cycle-depth rows (#556)
Freeze acyclic JSON.stringify chains at depths 512, 1024, 2048, and 4096. Graph construction runs before ten warmups and the scored invocation; every job validates exact output length, leaf offset, delimiters, and checksum. Add a depth-4096 real ancestor-cycle row that requires TypeError and a shallow 4096-element repeated-alias control that must serialize legally. Frozen one-job checksums are 8946, 17650, 35058, 69874, 1004096, and 45243. Parent diagnostics retire 7.86M, 21.25M, 64.14M, and 227.62M instructions across the depth rows, exposing accelerating membership work. The complete benchmark validation family and 18/18 structural matrix pass. Flips 0 test262 cases. Issue: #556
1 parent 5963819 commit 4be2bc6

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

‎bench/representative_comparison.js‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,84 @@ function representativeJsonStringifyReplacerMembership(jobs, lane) {
274274
return total;
275275
}
276276

277+
// JSON.stringify's cycle rule is active-ancestor membership, not global graph
278+
// visitation. Selection constructs the graph once before all ten warmups and
279+
// the scored invocation; every job performs and validates a real stringify.
280+
var representativeJsonStringifyGraph = null;
281+
var representativeJsonStringifyDepth = 0;
282+
var representativeJsonStringifyExpectedLength = 0;
283+
var representativeJsonStringifyExpectedLeafOffset = 0;
284+
function selectRepresentativeJsonStringifyDepth(depth, circular) {
285+
var leaf = { leaf: 1 };
286+
var root = leaf;
287+
for (var level = 1; level < depth; level = level + 1)
288+
root = { next: root };
289+
if (circular) leaf.next = root;
290+
representativeJsonStringifyGraph = root;
291+
representativeJsonStringifyDepth = depth;
292+
representativeJsonStringifyExpectedLength = depth * 9 + 1;
293+
representativeJsonStringifyExpectedLeafOffset = (depth - 1) * 8 + 1;
294+
return circular ? representativeJsonStringifyCycle : representativeJsonStringifyAcyclic;
295+
}
296+
297+
function representativeJsonStringifyAcyclic(jobs, lane) {
298+
var total = 0;
299+
for (var job = 0; job < jobs; job = job + 1) {
300+
var encoded = JSON.stringify(representativeJsonStringifyGraph);
301+
var leafOffset = encoded.indexOf("\"leaf\":1");
302+
if (encoded.length !== representativeJsonStringifyExpectedLength ||
303+
leafOffset !== representativeJsonStringifyExpectedLeafOffset ||
304+
encoded.charCodeAt(0) !== 123 || encoded.charCodeAt(encoded.length - 1) !== 125)
305+
throw new Error("JSON.stringify depth witness drift");
306+
total = total + encoded.length + leafOffset +
307+
encoded.charCodeAt(0) + encoded.charCodeAt(encoded.length - 1) + lane;
308+
}
309+
return total;
310+
}
311+
312+
function representativeJsonStringifyCycle(jobs, lane) {
313+
var total = 0;
314+
for (var job = 0; job < jobs; job = job + 1) {
315+
var threw = false;
316+
try {
317+
JSON.stringify(representativeJsonStringifyGraph);
318+
} catch (error) {
319+
if (!(error instanceof TypeError)) throw error;
320+
threw = true;
321+
}
322+
if (!threw) throw new Error("JSON.stringify accepted an ancestor cycle");
323+
total = total + 1000000 + representativeJsonStringifyDepth + lane;
324+
}
325+
return total;
326+
}
327+
328+
function selectRepresentativeJsonStringifyShallow(width) {
329+
var siblings = [];
330+
var shared = { leaf: 1 };
331+
for (var index = 0; index < width; index = index + 1)
332+
siblings.push(shared);
333+
representativeJsonStringifyGraph = siblings;
334+
representativeJsonStringifyDepth = width;
335+
representativeJsonStringifyExpectedLength = width * 11 + 1;
336+
representativeJsonStringifyExpectedLeafOffset = 2;
337+
return representativeJsonStringifyShallow;
338+
}
339+
340+
function representativeJsonStringifyShallow(jobs, lane) {
341+
var total = 0;
342+
for (var job = 0; job < jobs; job = job + 1) {
343+
var encoded = JSON.stringify(representativeJsonStringifyGraph);
344+
var leafOffset = encoded.indexOf("\"leaf\":1");
345+
if (encoded.length !== representativeJsonStringifyExpectedLength ||
346+
leafOffset !== representativeJsonStringifyExpectedLeafOffset ||
347+
encoded.charCodeAt(0) !== 91 || encoded.charCodeAt(encoded.length - 1) !== 93)
348+
throw new Error("JSON.stringify shallow witness drift");
349+
total = total + encoded.length + leafOffset +
350+
encoded.charCodeAt(0) + encoded.charCodeAt(encoded.length - 1) + lane;
351+
}
352+
return total;
353+
}
354+
277355
function representativeCollections(jobs, lane, variant) {
278356
var total = 0;
279357
for (var job = 0; job < jobs; job = job + 1) {
@@ -901,6 +979,12 @@ function benchmarkFunction(name) {
901979
if (name === "representative_json_escaped_strings") return representativeJsonEscapedStrings;
902980
if (name === "representative_json_stringify_replacer") return representativeJsonStringifyReplacer;
903981
if (name === "representative_json_stringify_replacer_membership") return representativeJsonStringifyReplacerMembership;
982+
if (name === "representative_json_stringify_depth_512") return selectRepresentativeJsonStringifyDepth(512, false);
983+
if (name === "representative_json_stringify_depth_1024") return selectRepresentativeJsonStringifyDepth(1024, false);
984+
if (name === "representative_json_stringify_depth_2048") return selectRepresentativeJsonStringifyDepth(2048, false);
985+
if (name === "representative_json_stringify_depth_4096") return selectRepresentativeJsonStringifyDepth(4096, false);
986+
if (name === "representative_json_stringify_cycle_4096") return selectRepresentativeJsonStringifyDepth(4096, true);
987+
if (name === "representative_json_stringify_shallow_4096") return selectRepresentativeJsonStringifyShallow(4096);
904988
if (name === "representative_collections") return function (jobs, lane) { return representativeCollections(jobs, lane, 0); };
905989
if (name === "representative_collections_variant") return function (jobs, lane) { return representativeCollections(jobs, lane, 1); };
906990
if (name === "representative_strong_identity_collections") return function (jobs, lane) { return representativeStrongIdentityCollections(jobs, lane, 0); };

0 commit comments

Comments
 (0)