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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user