From b3b7514f6c039fed4d70ebfb6b76040b4be20458 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 23:48:10 +0000 Subject: [PATCH] Optimize numeric search with cached evaluate results Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src/ui/search.ts | 2 +- src/workspace.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ui/search.ts b/src/ui/search.ts index 0297020..7b332a0 100644 --- a/src/ui/search.ts +++ b/src/ui/search.ts @@ -49,7 +49,7 @@ function searchAllSheets(deps: SearchDeps, query: string): SearchHit[] { const th = rq.threshold.value; const hits: SearchHit[] = []; for (const doc of docs) { - const results = deps.workspace.evaluateSheet(doc.id, doc.text); + const results = deps.workspace.getCachedResults(doc); const lines = doc.text.split("\n"); for (let i = 0; i < results.length; i++) { const r = results[i]; diff --git a/src/workspace.ts b/src/workspace.ts index fc688b7..1791450 100644 --- a/src/workspace.ts +++ b/src/workspace.ts @@ -15,6 +15,7 @@ interface SheetExports { vars: Map; total: Value | null; last: Value | null; + results: LineResult[]; } const XREF_SCAN_RE = /@(?:\[([^\]]+)\]|([\p{L}_][\p{L}\d_]*))\./gu; @@ -40,6 +41,10 @@ export class Workspace { } } + getCachedResults(sheet: SheetSource): LineResult[] { + return this.exportsFor(sheet).results; + } + /** Drop cached exports for a sheet and everything that transitively depends on it. */ invalidate(sheetId: string): void { const dirty = new Set([sheetId]); @@ -146,7 +151,7 @@ export class Workspace { break; } } - const exports: SheetExports = { vars, total: this.engine.totalValueOf(results), last }; + const exports: SheetExports = { vars, total: this.engine.totalValueOf(results), last, results }; // A cycle-interrupted pass produces incomplete/wrong exports (dropped // assignments, missing total) — don't let it poison the cache. Re-evaluate // fresh on every query until the cycle is actually broken by an edit.