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 authored and GitHub committed 2026-11-22 03:43:13 -05:00
1 parent 79887f7a3b
commit fde2c87b86
17 files changed
+1860 -535

No files matched your search

@@ -1,3 +1,10 @@
import {
canBorrowParsedJsonSnapshot,
freezeJsonSnapshot,
immutableJsonSnapshotMember,
isImmutableJsonSnapshot,
} from "../../domain/immutableJson.js";
import type { JsonValue } from "../../domain/jsonValue.js";
import {
JAVASCRIPT_APPLICATION_PROVIDER,
JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER,
@@ -125,41 +132,70 @@ export const parseApplicationGraphEvidence = (
const evidence = parseEvidenceInput(input);
const owned = ownedApplicationSources.get(evidence);
if (owned !== undefined) return owned;
const immutable =
isImmutableEvidence(evidence) && isImmutableJsonSnapshot(evidence);
let source: ApplicationGraphEvidenceSource;
if (evidence.operation === "analyze_javascript_application") {
requirePredicate(evidence, "rea.javascript-application-analysis", path);
requireProvider(evidence, JAVASCRIPT_APPLICATION_PROVIDER, path);
return staticApplicationSource(evidence, path);
}
if (evidence.operation === "reconcile_javascript_runtime") {
source = staticApplicationSource(evidence, path, immutable);
} else if (evidence.operation === "reconcile_javascript_runtime") {
requirePredicate(evidence, "rea.javascript-runtime-reconciliation", path);
requireProvider(
evidence,
JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER,
path,
);
return staticRuntimeSource(evidence, path);
}
if (evidence.operation === "project_managed_application_graph") {
source = staticRuntimeSource(evidence, path, immutable);
} else if (evidence.operation === "project_managed_application_graph") {
requirePredicate(evidence, "rea.managed-application-graph", path);
requireProvider(evidence, MANAGED_WORKFLOW_PROVIDER, path);
return managedApplicationSource(evidence, path);
source = managedApplicationSource(evidence, path, immutable);
} else {
throw invalidEvidence(
path,
"operation",
"Expected authenticated JavaScript analysis, runtime reconciliation, or managed application graph Evidence.",
);
}
throw invalidEvidence(
path,
"operation",
"Expected authenticated JavaScript analysis, runtime reconciliation, or managed application graph Evidence.",
);
if (immutable) {
const cached = Object.freeze(source);
ownedApplicationSources.set(evidence, cached);
return cached;
}
return source;
});
const borrowOrSealNormalizedResult = <Parsed extends JsonValue>(
evidence: Evidence,
parsed: Parsed,
immutable: boolean,
memberKeys: readonly string[],
): Parsed => {
if (!immutable) return parsed;
const snapshot = immutableJsonSnapshotMember(evidence, "normalized_result");
const owned =
snapshot !== undefined && canBorrowParsedJsonSnapshot(snapshot, parsed)
? (snapshot as Parsed)
: freezeJsonSnapshot(parsed);
for (const key of memberKeys) immutableJsonSnapshotMember(owned, key);
return owned;
};
const staticApplicationSource = (
evidence: Evidence,
path: readonly (string | number)[],
immutable: boolean,
): ApplicationGraphEvidenceSource => {
const result = parseCallerValue(
const parsed = parseCallerValue(
(input) => javascriptApplicationAnalysisResultSchema.parse(input),
evidence.normalized_result,
[...path, "normalized_result"],
);
const result = borrowOrSealNormalizedResult(evidence, parsed, immutable, [
"graph",
"semantic_graph",
]);
return staticApplicationSourceForResult(evidence, result, path);
};
@@ -201,6 +237,7 @@ const staticApplicationSourceForResult = (
const staticRuntimeSource = (
evidence: Evidence,
path: readonly (string | number)[],
immutable: boolean,
): ApplicationGraphEvidenceSource => {
if (
evidence.authority !== "analyst-inference" ||
@@ -211,11 +248,14 @@ const staticRuntimeSource = (
"authority",
"Runtime reconciliation Evidence must use analyst-inference authority and inferred confidence.",
);
const result = parseCallerValue(
const parsed = parseCallerValue(
(input) => javascriptRuntimeReconciliationResultSchema.parse(input),
evidence.normalized_result,
[...path, "normalized_result"],
);
const result = borrowOrSealNormalizedResult(evidence, parsed, immutable, [
"graph",
]);
assertResultEvidenceLinksInEnvelope(
result.evidence_links,
evidence,
@@ -243,6 +283,7 @@ const staticRuntimeSource = (
const managedApplicationSource = (
evidence: Evidence,
path: readonly (string | number)[],
immutable: boolean,
): ApplicationGraphEvidenceSource => {
if (
evidence.authority !== "analyst-inference" ||
@@ -253,11 +294,14 @@ const managedApplicationSource = (
"authority",
"Managed application graph Evidence must use analyst-inference authority and inferred confidence.",
);
const result = parseCallerValue(
const parsed = parseCallerValue(
(input) => managedApplicationGraphResultSchema.parse(input),
evidence.normalized_result,
[...path, "normalized_result"],
);
const result = borrowOrSealNormalizedResult(evidence, parsed, immutable, [
"graph",
]);
assertResultEvidenceLinksInEnvelope(
result.evidence_links,
evidence,