perf(analysis-view): reuse validated immutable parents

Reuse successful format validation for exact authenticated immutable native and imported JavaScript results. Preserve schema normalization and alias topology before borrowing source data; owned JavaScript graph wrappers retain their existing metadata-normalization path.

Validated with 130 source tests, 36 compiled CLI/MCP boundary tests, 27 default-deadline integration tests, full checks/docs/build, and paired real retained-Evidence tasks. The report preserves cold costs, previous negative results, incomplete resource-stopped runs, and the limits of offline token estimates.

Fixes #4810

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
Ysopwnable
2026-10-18 14:38:00 +08:00
committed by GitHub
parent b83b9caf4a
commit 8f7d12e30d
13 changed files with 1473 additions and 22 deletions
@@ -1,4 +1,5 @@
import { z } from "zod";
import { canBorrowParsedJsonSnapshot } from "../immutableJson.js";
import {
javascriptApplicationGraphSchema,
@@ -172,21 +173,43 @@ const ownedAnalysisResultShape = applicationAnalysisResultShape.extend({
),
});
// One successful interpretation per exact immutable source. Weak keys retain
// neither a second graph nor a source beyond its Evidence lifetime.
const validatedImmutableResults = new WeakSet<object>();
const isValidatedImmutableResult = (
input: unknown,
): input is JavaScriptApplicationAnalysisResult =>
typeof input === "object" &&
input !== null &&
validatedImmutableResults.has(input);
/** Reuse exact owned graphs while validating metadata and cross-graph bindings. */
export function* parseOwnedJavaScriptApplicationAnalysisSteps(
input: unknown,
): Generator<void, JavaScriptApplicationAnalysisResult> {
if (isValidatedImmutableResult(input)) return input;
const prepared = ownedAnalysisResultShape.safeParse(input);
if (!prepared.success)
return javascriptApplicationAnalysisResultSchema.parse(input);
const issues: BindingIssue[] = [];
yield* checkApplicationBindingsSteps(prepared.data, {
addIssue: (issue) => {
issues.push(issue);
},
});
if (issues.length > 0) throw new z.ZodError(issues);
return prepared.data;
if (prepared.success) {
const issues: BindingIssue[] = [];
yield* checkApplicationBindingsSteps(prepared.data, {
addIssue: (issue) => {
issues.push(issue);
},
});
if (issues.length > 0) throw new z.ZodError(issues);
// Keep this existing fast path and its metadata normalization. Rewalking
// already owned graphs just to borrow the wrapper would add full-graph work.
return prepared.data;
}
const result = javascriptApplicationAnalysisResultSchema.parse(input);
// Borrow only if parsing preserved the exact representation. A future schema
// default/normalization must still return its parsed value, without caching.
// Admission follows full validation, including completion of yielding checks.
if (canBorrowParsedJsonSnapshot(input, result)) {
validatedImmutableResults.add(input);
return input;
}
return result;
}
/** Parsed public JavaScript application analysis request. */