mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 19:41:20 -05:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user