perf(ci): optimize semantic graph construction, directory containment checks, gate checkouts, and boundary stragglers (#11851)

* perf(javascript): avoid redundant semantic graph validation and node hashing

* perf(resources): deduplicate directory containment checks and root lstat calls

* perf(ci): trace script fixture modules, sparse-checkout gate jobs, and parallelize built doc checks

* perf(tests): memoize live MCP doctor expectations and reuse CLI and verifier compilation

* fix(ci): enforce containment after skipped entries, validate interned contexts, and supervise doc and verifier teardowns

* fix(docs): decode buffered check output once to preserve multi-byte UTF-8
This commit is contained in:
morluto authored and GitHub committed 2026-11-17 14:57:30 -05:00
1 parent 015f726a9e
commit 84ee604c6d
25 files changed
+1650 -259

No files matched your search

@@ -4,11 +4,11 @@ import type { JavaScriptApplicationGraph } from "../../domain/javascript/javascr
import type { JsonValue } from "../../domain/jsonValue.js";
import { javascriptDisplayText } from "../../domain/javascript/javascriptAstValues.js";
import {
createJavaScriptSemanticGraphNode,
createJavaScriptSemanticGraphUnknown,
createJavaScriptSemanticGraphRelation,
createOwnedJavaScriptSemanticGraphNode,
createOwnedJavaScriptSemanticGraphUnknown,
createOwnedJavaScriptSemanticGraphRelation,
JavaScriptSemanticEvidenceContextRegistry,
javaScriptSemanticNodeId,
withJavaScriptSemanticNodeApplicationIds,
} from "../../domain/javascript/javascriptSemanticGraph.js";
import type {
JavaScriptSemanticGraphNode,
@@ -29,6 +29,7 @@ import {
/** Mutable local projection state hidden from graph callers. */
export interface SemanticGraphProjectionState {
readonly nodes: Map<string, JavaScriptSemanticGraphNode>;
readonly nodesByLookupKey: Map<string, JavaScriptSemanticGraphNode>;
readonly relations: Map<string, JavaScriptSemanticGraphRelation>;
readonly unknowns: Map<string, JavaScriptSemanticGraphUnknown>;
/** Absolute retained unknown count allowed during this file; null outside admission. */
@@ -82,6 +83,7 @@ export interface SemanticRelationConstructionInput {
export const createSemanticGraphProjectionState =
(): SemanticGraphProjectionState => ({
nodes: new Map(),
nodesByLookupKey: new Map(),
relations: new Map(),
unknowns: new Map(),
unknownCapacity: null,
@@ -99,18 +101,26 @@ export const bindSemanticGraphApplicationNodes = (
applicationGraph.nodes,
);
for (const [identifier, node] of state.nodes) {
state.nodes.set(identifier, {
...node,
application_node_ids: [
...(applicationNodeIdsByLocation.get(
applicationLocationKey(
node.identity.artifact_sha256,
node.identity.module_path,
node.identity.source_range,
),
) ?? []),
],
});
const matched = applicationNodeIdsByLocation.get(
applicationLocationKey(
node.identity.artifact_sha256,
node.identity.module_path,
node.identity.source_range,
),
);
if (matched === undefined && node.application_node_ids.length === 0)
continue;
const updated = withJavaScriptSemanticNodeApplicationIds(
node,
matched ?? [],
);
if (updated !== node) {
state.nodes.set(identifier, updated);
state.nodesByLookupKey.set(
semanticNodeIdentityLookupKey(updated),
updated,
);
}
}
};
@@ -120,7 +130,7 @@ export const constructSemanticGraphNode = (
input: SemanticNodeConstructionInput,
state: SemanticGraphProjectionState,
): JavaScriptSemanticGraphNode =>
createJavaScriptSemanticGraphNode(
createOwnedJavaScriptSemanticGraphNode(
{
kind: input.kind,
identity: {
@@ -139,22 +149,40 @@ export const constructSemanticGraphNode = (
state.evidenceContexts,
);
const semanticNodeLookupKey = (
kind: JavaScriptSemanticGraphNode["kind"],
artifactSha256: string,
modulePath: string,
sourceRange: JavaScriptSourceRange | null,
roleKey: string,
): string =>
`${kind}:${artifactSha256}:${String(modulePath.length)}:${modulePath}:${sourceRange === null ? "-" : javascriptSourceRangeKey(sourceRange)}:${roleKey}`;
export const semanticNodeIdentityLookupKey = (
node: Pick<JavaScriptSemanticGraphNode, "kind" | "identity">,
): string =>
semanticNodeLookupKey(
node.kind,
node.identity.artifact_sha256,
node.identity.module_path,
node.identity.source_range,
node.identity.role_key,
);
/** Reuse retained identities and reject exhausted budgets before allocation. */
export const retainSemanticGraphNode = (
state: SemanticGraphProjectionState,
file: JavaScriptArtifactFile,
input: SemanticNodeConstructionInput,
): JavaScriptSemanticGraphNode | null => {
const identifier = javaScriptSemanticNodeId({
kind: input.kind,
identity: {
artifact_sha256: file.sha256,
module_path: file.path,
source_range: input.location,
role_key: input.roleKey,
},
});
const existing = state.nodes.get(identifier);
const lookupKey = semanticNodeLookupKey(
input.kind,
file.sha256,
file.path,
input.location,
input.roleKey,
);
const existing = state.nodesByLookupKey.get(lookupKey);
if (existing !== undefined) return existing;
if (typeof state.fileNodeBudget === "number" && state.fileNodeBudget <= 0) {
state.fileNodesDropped = true;
@@ -163,6 +191,7 @@ export const retainSemanticGraphNode = (
return addSemanticGraphNode(
state,
constructSemanticGraphNode(file, input, state),
lookupKey,
);
};
@@ -170,6 +199,7 @@ export const retainSemanticGraphNode = (
export const addSemanticGraphNode = (
state: SemanticGraphProjectionState,
node: JavaScriptSemanticGraphNode,
knownLookupKey?: string,
): JavaScriptSemanticGraphNode | null => {
const existing = state.nodes.get(node.node_id);
if (existing !== undefined) return existing;
@@ -182,6 +212,10 @@ export const addSemanticGraphNode = (
state.fileNodeBudget = budget - 1;
}
state.nodes.set(node.node_id, node);
state.nodesByLookupKey.set(
knownLookupKey ?? semanticNodeIdentityLookupKey(node),
node,
);
return node;
};
@@ -198,7 +232,7 @@ export const addSemanticGraphRelation = (
input.source.node_id === input.target.node_id
)
return;
const value = createJavaScriptSemanticGraphRelation(
const value = createOwnedJavaScriptSemanticGraphRelation(
{
source_node_id: input.source.node_id,
target_node_id: input.target.node_id,
@@ -252,7 +286,7 @@ export const addSemanticGraphUnknown = (
});
return;
}
const unknown = createJavaScriptSemanticGraphUnknown(
const unknown = createOwnedJavaScriptSemanticGraphUnknown(
input,
state.evidenceContexts,
);
@@ -267,7 +301,7 @@ export const addSemanticFallbackRoot = (
): void => {
const node = addSemanticGraphNode(
state,
createJavaScriptSemanticGraphNode(
createOwnedJavaScriptSemanticGraphNode(
{
kind: "module",
identity: {