perf(domain): reuse canonical JSON key encodings

Reuse exact JSON key encodings within the existing 8,192-code-unit digest-buffer quantum and avoid ordinary member value frames. Preserve canonical bytes and cooperative yielding; resume objects when a pending property is omitted.

Flameox paired experiments establish a local digest-workload improvement, with complete-result/EvidenceID oracles unchanged. Full CLI acceleration and billed token reductions are not claimed.

Refs #1065.
This commit is contained in:
Ysopwnable
2026-10-11 11:40:47 +08:00
committed by GitHub
parent ea06264a56
commit 89ea2cad19
2 changed files with 52 additions and 13 deletions
@@ -21,6 +21,12 @@ describe("cooperative canonical JSON digest", () => {
),
{ payload: `${"x".repeat(8191)}𐀀${"\n\ud800".repeat(20_000)}` },
{ [`${"x".repeat(8191)}𐀀${"\n".repeat(20_000)}`]: "value" },
Object.fromEntries(
Array.from({ length: 512 }, (_, index) => [
`escaped\n\"\\𐀀${"x".repeat(32)}${index}`,
{ repeated: index },
]),
),
];
it.each(values.map((value) => ({ value })))(
"preserves complete canonical meaning (%#)",
@@ -55,6 +61,18 @@ describe("cooperative canonical JSON digest", () => {
expect(steps.next().done).toBe(true);
});
it("continues object hashing when a pending property is omitted", () => {
const value: { [key: string]: JsonValue } = {
a: "x".repeat(32_768),
b: 1,
c: { retained: true },
};
const steps = canonicalJsonDigestSteps(value);
expect(steps.next().done).toBe(false);
delete value.b;
expect(complete(steps)).toBe(digestCanonicalValue(value));
});
it("rejects sparse arrays, nonfinite numbers and cycles", () => {
const sparse: JsonValue[] = [];
sparse.length = 2;