mirror of
https://github.com/morluto/rea
synced 2026-10-27 06:33:32 -04:00
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:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user