t3code icon indicating copy to clipboard operation
t3code copied to clipboard

perf(web): Command Palette thread search misses all WeakMap caches on every keystroke

Open AymanKhan9 opened this issue 1 week ago • 1 comments

In apps/web/src/components/CommandPalette.logic.ts, buildThreadActionItems constructs a new wrapper object ({ ...thread, latestUserMessageAt: thread.latestUserMessageAt ?? null, opens: thread.opens ?? null }) before calling threadSearchSubject(...).

Because threadSearchSubject (packages/client-runtime/src/state/threadSearch.ts) memoizes each thread's ThreadSearchSubject in a WeakMap keyed by thread object identity — and packages/shared/src/paletteSearch.ts caches WeightedSearchField[] and folded/tokenized SearchField instances per ThreadSearchSubject — passing a newly spread object causes all three cache layers to miss on 100% of threads on every keystroke in CommandPaletteThreadItems.tsx.

Making latestUserMessageAt, latestUserAuthoredMessageAt, and opens optional on ThreadSearchShell (their consumers already handle undefined) and passing thread directly restores the WeakMap cache hits on every keystroke.

AymanKhan9 avatar Nov 24 '26 18:11 AymanKhan9

Fixed by #42988, now on main: With unchanged threads, typing successive characters in the command palette now reuses the same thread items and search subjects, so the weighted-field and tokenization caches survive keystrokes instead of missing for every thread.

juliusmarminge avatar Nov 25 '26 20:11 juliusmarminge