perf(clients): thread search reuses per-thread fields across keystrokes #26936
main fromrefs/pull/26936/head·merged by maria-rcks View on GitHubProblem#
Every keystroke in the sidebar thread search, the composer @thread menu, mobile threadListV2 and the palette's thread ranking runs threadSearchSubject, scoreThreadSearch and rankSearchItems for every thread. Each call rebuilt the subject (Date.parse, pull request list, key concatenation), the field list and the prepared arrays, re-split and regex-replaced the query, allocated an empty array per non-matching thread via flatMap, and matchJoinedWords walked every character of every title.
Fix#
packages/client-runtime/src/state/threadSearch.ts:threadSearchSubjectis cached per shell in aWeakMap, invalidated whenprojectTitle,environmentLabelorclaimThreadOpenchanges.packages/shared/src/paletteSearch.ts: weighted fields are cached per subject, the tokenised query is cached for the current query,rankSearchGroupspushes matches instead offlatMap,matchReferenceiterates in place,matchJoinedWordsjumps between candidate positions withindexOf, andmatchTokenevaluates its boundary check lazily.
No ranking, scoring or explain() change.
Measurements#
Real thread titles from a copy of a real database, 5 typed queries (73 keystrokes); the harness mirrors searchSidebarThreads and builds a subject per thread per keystroke as the sidebar does. 5 interleaved processes x 7 rounds, warmup dropped, median; allocation is summed heap growth between GCs.
| Threads | Base | New | Time | Base alloc | New alloc | Alloc |
|---|---|---|---|---|---|---|
| 300 | 22.8 ms | 10.2 ms | 2.2x | 69.9 MB | 21.5 MB | -69% |
| 3,000 | 230 ms | 99 ms | 2.3x | 687 MB | 182 MB | -74% |
| 10,000 | 733 ms | 304 ms | 2.4x | 2,287 MB | 592 MB | -74% |
What limits the new number: the native field.text.indexOf(token) scan in matchToken plus match-result allocation for threads that match. A cache miss (a fresh shell object) costs about 0.13 ms per 3,000 shells. The subject cache only helps while shell objects keep their identity across keystrokes; the command palette spreads each thread into a new object, so it misses there but builds items once per item build rather than per keystroke.
Scope and approval#
No triaged issue or maintainer-approved discussion exists for this; it is a focused, behaviour-preserving performance fix of one measured hot path (one problem, one PR, output identical to main as shown under Validation, no new setting, wire change or UI). Dedupe: I searched all open, merged and closed PRs by file and symbol and found none covering this function.
Validation#
- Old vs new module compared on 2,880 cases over 360 queries (typos on/off, picks on/off, joined words, PR and ID references, CJK, accents), including
rankSearchItems,scoreSearchTermsandexplain(): 0 mismatches.claimThreadOpeninvalidation checked against the old behaviour. - One assertion block added to the existing "ranks recent threads by this client's own latest open" test.
vp run check:changed: format, lint, knip, typecheck, tests pass; 211 tests across paletteSearch, threadSearch, composerThreadItems, mobilethreadListV2,commandPaletteItems,CommandPalette.logic,Sidebar.logic.- Open #16858 edits
threadSearch.tsfor search qualifiers (different functions); merged #24343 added the search. No PR in any state optimises this ranking path.
Authored with Claude Sonnet 5.5 via the Claude Code harness in T3 Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 6d450a4
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
fa4044f1-ffa7-4a99-a496-c0726739fe38
Commits-
Reviewing files that changed from the base of the PR and between 6d450a4284852af137b2f3407fddd89eb76e7644 and 63f325db0cb2aa48f3988459c1c84d693200ce7f.
Files selected for processing: 3-
packages/client-runtime/src/state/threadSearch.test.tspackages/client-runtime/src/state/threadSearch.tspackages/shared/src/paletteSearch.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
-
Walkthrough
-
Thread search now invalidates cached subjects when local opens or subject labels change. Shared palette search caches prepared fields and query data, updates matching routines, and collects group matches with an explicit loop.
Changes: Thread search
Priority:Layer / File(s) Summary Thread subject cache invalidation
packages/client-runtime/src/state/threadSearch.ts,packages/client-runtime/src/state/threadSearch.test.tsLocal opens increment a version used to validate cached subjects. Subjects are rebuilt when the thread, project title, environment label, or version changes. Tests cover a later local open and a supplied project title. Search field and query preparation
packages/shared/src/paletteSearch.tsWeighted fields are prepared on demand, and normalized query tokens are cached. Token matching and joined-word matching use updated occurrence checks. Thread scoring and group ranking
packages/shared/src/paletteSearch.tsThread fields and transformed queries are cached. Reference matching checks IDs and pull-request references directly. Group matches are collected with an explicit loop. LowEstimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Possibly related PRs
- pingdotgg/t3code#24343: Adds the shared scorer and thread-search subject used by this change.
- pingdotgg/t3code#24723: Adds project scopes and environment labels to client thread search, which are inputs to subject caching here.
- pingdotgg/t3code#21626: Caches pull-request search terms; this change adds caching to shared thread-search fields and queries.
Suggested reviewers:
t3dotgg
Merge Risk:
Minimal · up to63f32-
No actionable issue is established for the search changes; the PR is mergeable after normal checks.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the primary change: reusing per-thread search fields across keystrokes for client thread search. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Description check The description is complete and directly addresses the template requirements. It explains the problem, implementation, scope and approval rationale, focused verification, measured results, and agent u… Full details: Description check
-
Explanation
The description is complete and directly addresses the template requirements. It explains the problem, implementation, scope and approval rationale, focused verification, measured results, and agent usage. It uses “Fix” and “Validation” instead of the template headings “Change” and “Verification,” but the required information is present.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
@t3dotgg ready for review. Thread search (sidebar, composer
@thread, mobile list, palette) rebuilt each thread's subject and fields on every keystroke; they are now cached per shell. 3,000 threads: 230 ms to 99 ms (2.3x) and 687 MB to 182 MB allocated (-74%), with identical results, scores andexplain()output over 2,880 comparisons. Builds on your #24343 search. Related tracker: #9661. The CI workflows on this fork PR showaction_required, so they are waiting on a maintainer to approve the run. CodeRabbit and Macroscope are done with no open findings (Macroscope approved).Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
verified head
63f325db0cb2aa48f3988459c1c84d693200ce7fas-is on linux with repository playwright and/usr/bin/google-chrome.- ran
github/main(5732bbee39) in a separate worktree first, then stopped it before starting the exact pr head. installed dependencies withvp i. each run used isolated state. - added a real git project through the app and created three threads with actual codex
gpt-6.1-solturns on each revision. no mocks or seeded thread fixtures. - both revisions returned matching thread results for
pal,pale,palet,palette,cafe,cafesearch,beta, and a no-match query. checked sidebar keyboard selection, command-palette selection, accent folding, joined words, and clearing search. - checked cache invalidation after renaming a warmed thread: the new joined title matched; restoring its original title removed that match.
- selected a composer thread result and submitted the reference to codex. the real provider completed
t3_thread_readand returned the selected thread's exact assistant marker. - browser precise coverage confirmed repeated preparation on main (525
prepareSearchFieldcalls during the query sequence). the warm pr sequence scored threads 368 times with zero field preparations. these are observed call counts, not a latency benchmark. vp run check:changed 6d450a4284852af137b2f3407fddd89eb76e7644passed throughblacksmith-check: format, lint, knip, affected-package typechecks, and 45 tests. no source changes or pushes were needed.
provider transcript from the running pr server:
04:21:03 turn/start model=gpt-6.1-sol 04:21:15 t3_thread_read status=completed 04:21:19 turn/completed status=completed answer="palette verification gamma."main, matching search data:

pr, matching search data:

interaction recording, 3x playback with pauses shortened:


Not verified#
native ios/android and electron shells were not exercised on this linux vm. remote/relay and tunnel modes, linked pull-request searches, other providers, and large-library latency/allocation claims were not exercised. the small real dataset proves the client flow and cache reuse, not the advertised multi-thousand-thread speedup.
- ran
maria-rcks merged this9504a09
maria-rcks closed this
Sign in to join this conversation.
Approvability#
Verdict: Approved at
63f325dMacroscope's review found this PR approvable — Thread search reuses subjects, prepared fields and query processing across keystrokes to reduce repeated work. The changes remain within in-memory search ranking, without changing product defaults or persistent data.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).