perf(javascript): index feature, semantic, IPC, and source map lookups (#13319)

perf(javascript): eliminate double preload AST pass and index feature/semantic/IPC/sourcemap lookups
This commit is contained in:
morluto
2026-11-22 03:43:13 -05:00
committed by GitHub
parent 79887f7a3b
commit fde2c87b86
17 changed files with 1860 additions and 535 deletions
@@ -2,6 +2,7 @@ import { digestCanonicalValue } from "../canonicalDigest.js";
import type { JavaScriptSemanticGraph } from "./javascriptSemanticGraph.js";
import type { JavaScriptSemanticGraphNode } from "./javascriptSemanticGraphSchemas.js";
import { getSemanticGraphIndex } from "./javascriptSemanticGraphIndex.js";
import { uniqueSorted } from "../canonicalOrdering.js";
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
import type { JavaScriptSemanticQueryInput } from "./javascriptSemanticQuerySchemas.js";
@@ -38,6 +39,8 @@ export const resolveJavaScriptSemanticQuerySeeds = (
graph: JavaScriptSemanticGraph,
input: JavaScriptSemanticQueryInput,
): string[] => {
const index = getSemanticGraphIndex(graph);
if (index !== undefined) return resolveIndexedSeeds(index, input.seed);
const fingerprintFunctions = new Set(
input.seed.kind === "function"
? graph.fingerprints
@@ -82,6 +85,29 @@ export const resolveJavaScriptSemanticQuerySeeds = (
.sort(compareUnicodeCodePoints);
};
const resolveIndexedSeeds = (
index: NonNullable<ReturnType<typeof getSemanticGraphIndex>>,
seed: JavaScriptSemanticQueryInput["seed"],
): string[] => {
if (seed.kind === "semantic-node") {
const node = index.getNodesById().get(seed.node_id);
return node === undefined ? [] : [node.node_id];
}
const seeds = index.getSeedIndex();
if (seed.kind === "application-node")
return [...(seeds.byApplicationNodeId.get(seed.node_id) ?? [])];
if (seed.kind === "function")
return [...(seeds.byFingerprint.get(seed.fingerprint_sha256) ?? [])];
if (seed.kind === "literal")
return [...(seeds.byLiteral.get(seed.value) ?? [])];
if (seed.kind === "property")
return [...(seeds.byProperty.get(seed.name) ?? [])];
if (seed.kind === "endpoint")
return [...(seeds.byEndpoint.get(seed.value) ?? [])];
if (seed.kind === "event") return [...(seeds.byEvent.get(seed.name) ?? [])];
return [...(seeds.byBoundaryField.get(seed.field) ?? [])];
};
const seedMatches = (
node: JavaScriptSemanticGraphNode,
input: JavaScriptSemanticQueryInput,