perf(javascript): hash each semantic evidence context once (#1457)
The semantic graph's evidence-context registry canonicalized the full provenance context three times for every node, relation, unknown and fingerprint: once to hash its ID and twice more to compare against the stored row. A file has only a few distinct contexts, so nearly all of that work repeated a known answer. Interning now keys contexts by their canonical text. Each fact canonicalizes once, and only a new context is hashed and checked for a digest collision. IDs and output are unchanged; Obsidian's 334 MB Evidence is byte-identical and analysis drops from about 47.0 s to 44.4 s. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2781cad201
commit
ef96657d6b
2 files changed
+55
-8
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import type { ApplicationGraphEvidence } from "./javascriptApplicationEvidenceSchemas.js";
|
||||
import {
|
||||
JAVASCRIPT_SEMANTIC_NODE_KINDS,
|
||||
@@ -615,3 +616,42 @@ it.each(invalidGraphCases)(
|
||||
expect(issues(() => complete(steps))).toEqual(expected);
|
||||
},
|
||||
);
|
||||
|
||||
it("interns each distinct evidence context once under its content digest", () => {
|
||||
const registry = new JavaScriptSemanticEvidenceContextRegistry();
|
||||
const elsewhere: ApplicationGraphEvidence = {
|
||||
...evidence(),
|
||||
location: {
|
||||
available: true,
|
||||
value: {
|
||||
kind: "source-range",
|
||||
source: "other.js",
|
||||
start: { line: 7, column: 2 },
|
||||
end: { line: 7, column: 9 },
|
||||
},
|
||||
},
|
||||
};
|
||||
const first = registry.intern(evidence());
|
||||
const repeated = registry.intern(elsewhere);
|
||||
const reordered = registry.intern({
|
||||
...evidence("inferred"),
|
||||
limitations: [
|
||||
"Static reachability does not prove runtime execution.",
|
||||
"Static reachability does not prove runtime execution.",
|
||||
],
|
||||
});
|
||||
const inferred = registry.intern(evidence("inferred"));
|
||||
const { location: _location, ...context } = evidence();
|
||||
|
||||
expect(repeated.context_id).toBe(first.context_id);
|
||||
expect(repeated.location).toEqual(elsewhere.location);
|
||||
expect(reordered.context_id).toBe(inferred.context_id);
|
||||
expect(inferred.context_id).not.toBe(first.context_id);
|
||||
expect(first.context_id).toBe(
|
||||
`jsrg_evidence_${digestCanonicalValue(context, "test")}`,
|
||||
);
|
||||
expect(registry.contexts.map(({ context_id }) => context_id)).toEqual(
|
||||
[first.context_id, inferred.context_id].toSorted(),
|
||||
);
|
||||
expect(registry.resolve(repeated)).toEqual(elsewhere);
|
||||
});
|
||||
Reference in new issue
Block a user