Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(clients): thread search reuses per-thread fields across keystrokes #26936

Mergedhieu-lee(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/26936/headmerged by maria-rcks View on GitHub

Problem

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: threadSearchSubject is cached per shell in a WeakMap, invalidated when projectTitle, environmentLabel or claimThreadOpen changes.
  • packages/shared/src/paletteSearch.ts: weighted fields are cached per subject, the tokenised query is cached for the current query, rankSearchGroups pushes matches instead of flatMap, matchReference iterates in place, matchJoinedWords jumps between candidate positions with indexOf, and matchToken evaluates 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.

ThreadsBaseNewTimeBase allocNew allocAlloc
30022.8 ms10.2 ms2.2x69.9 MB21.5 MB-69%
3,000230 ms99 ms2.3x687 MB182 MB-74%
10,000733 ms304 ms2.4x2,287 MB592 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, scoreSearchTerms and explain(): 0 mismatches. claimThreadOpen invalidation 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, mobile threadListV2, commandPaletteItems, CommandPalette.logic, Sidebar.logic.
  • Open #16858 edits threadSearch.ts for 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

    2. Approvability

      Verdict: Approved at 63f325d

      Macroscope'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).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      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.ts
      • packages/client-runtime/src/state/threadSearch.ts
      • packages/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

      Layer / File(s)Summary
      Thread subject cache invalidation
      packages/client-runtime/src/state/threadSearch.ts, packages/client-runtime/src/state/threadSearch.test.ts
      Local 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.ts
      Weighted 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.ts
      Thread fields and transformed queries are cached. Reference matching checks IDs and pull-request references directly. Group matches are collected with an explicit loop.
      Priority: Low

      Estimated 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 to 63f32

      No actionable issue is established for the search changes; the PR is mergeable after normal checks.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary change: reusing per-thread search fields across keystrokes for client thread search.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe 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
      Comment `@coderabbitai help` to get the list of available commands.
    4. @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 and explain() output over 2,880 comparisons. Builds on your #24343 search. Related tracker: #9661. The CI workflows on this fork PR show action_required, so they are waiting on a maintainer to approve the run. CodeRabbit and Macroscope are done with no open findings (Macroscope approved).

    5. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      verified head 63f325db0cb2aa48f3988459c1c84d693200ce7f as-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 with vp i. each run used isolated state.
      • added a real git project through the app and created three threads with actual codex gpt-6.1-sol turns 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_read and returned the selected thread's exact assistant marker.
      • browser precise coverage confirmed repeated preparation on main (525 prepareSearchField calls 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 6d450a4284852af137b2f3407fddd89eb76e7644 passed through blacksmith-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:

      main sidebar search with three real codex threads

      pr, matching search data:

      pr sidebar search with the same three thread titles

      interaction recording, 3x playback with pauses shortened:

      pr sidebar search, palette selection, and composer thread reference

      codex returns the referenced thread marker through the real provider path

      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.

    6. maria-rcks merged this9504a09

    7. maria-rcks closed this

Sign in to join this conversation.