perf(workspace): cache sheet list during invalidate loop

Moved the evaluation of `this.sheets()` outside of the `while (changed)` invalidation loop to avoid redundant evaluations and allocations on deep dependency chains.

Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2026-08-19 11:35:51 +00:00
parent 868a34497b
commit 40d8141c32

View file

@ -54,10 +54,11 @@ export class Workspace {
invalidate(sheetId: string): void {
this.titleCache = null;
const dirty = new Set<string>([sheetId]);
const sheetsList = this.sheets();
let changed = true;
while (changed) {
changed = false;
for (const s of this.sheets()) {
for (const s of sheetsList) {
if (dirty.has(s.id)) continue;
for (const title of this.referencedTitles(s.text, s.id)) {
const target = this.findSheetByTitle(title);