From c10a13f2262ca7939a3b2258a037a809ca582cee Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 26 Aug 2026 14:09:14 +0000 Subject: [PATCH] perf(workspace): optimize sheet title caching to reduce string allocations Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src/workspace.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/workspace.ts b/src/workspace.ts index bc768b8..4c13bc7 100644 --- a/src/workspace.ts +++ b/src/workspace.ts @@ -29,6 +29,7 @@ export class Workspace { private resolving: Set = new Set(); private parsedRefsCache = new Map(); private titleCache: Map | null = null; + private lowerTitleCache = new Map(); constructor(private engine: SumEngine, private sheets: () => SheetSource[]) {} @@ -115,8 +116,14 @@ export class Workspace { const needle = title.trim().toLowerCase(); if (this.titleCache === null) { this.titleCache = new Map(); - for (const s of this.sheets()) { - const key = s.title.trim().toLowerCase(); + const currentSheets = this.sheets(); + for (let i = 0, len = currentSheets.length; i < len; i++) { + const s = currentSheets[i]; + let key = this.lowerTitleCache.get(s.title); + if (key === undefined) { + key = s.title.trim().toLowerCase(); + this.lowerTitleCache.set(s.title, key); + } if (!this.titleCache.has(key)) { this.titleCache.set(key, s); }