perf(shared): stop single-token message search at the best hit #28930
main fromrefs/pull/28930/head·merged by maria-rcks View on GitHubProblem#
Single-token thread-message searches collect every equal-quality occurrence and scan the rest of the message after finding the best possible whole-word hit. CPU profiles show this redundant lookup and span work dominates repeated-word messages. The open-PR catalog and targeted diffs showed no existing optimization of this lookup; #27267 changes the independent SQL prefilter.
Solution#
For exactly one token, retain the earliest best occurrence and stop once its quality cannot improve. Keep multi-token phrase/proximity collection, raw-versus-accent-folded preference, returned quality/offset, and client highlighting unchanged.
Local measurements compare the real baseline/current messageMatcher export with 90,414 exact grade/offset comparisons, alternating timing batches, consumed output and GC-inclusive allocation sampling. For 2,000 grades of a generated 31 KB message with repeated whole-word hits, the final confirmation is 7.53× faster with 74.3% fewer sampled allocated bytes. A 976-byte repeated-hit control is 4.44× faster with 59.6% fewer. One-hit and multi-token controls are near parity. In a sanitized, read-only local corpus, grading 1,112 messages for the is 2.42× faster with 38.5% fewer sampled bytes; other single-token queries range from 1.24–1.43×, and multi-token search is unchanged within measurement noise. These are matcher workloads, not whole-search SQL/network latency, retained heap, or whole-app multipliers. No private message text is published. Local benchmark code and artifacts are not part of this PR.
Tests were extended before implementation. The shared matcher and real-SQLite ThreadSearch suites pass 60 tests; vp run check:changed and a fresh batch of three independent Codex reviews are clean. The PR changes only production lookup logic and its existing tests; no schema, visible UI, permission or provider changes.
Built with GPT-6.1 Sol in the Codex harness through T3 Code.
TLDR#
https://github.com/user-attachments/assets/e1c37fcd-4efb-4a5e-a78a-ad3f1d6a85d9
- 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:S
Approvability#
Verdict: Approved at
a32e316Macroscope's review found this PR approvable — This optimizes single-token message searches by stopping at the first best-quality hit while leaving multi-token matching unchanged. Its effects are confined to search computation, with no product-default, permission, or persistent-data changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).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: fa31b66
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
fa604d0c-78b9-40c9-842b-2bb8bc2b8fbf
Commits-
Reviewing files that changed from the base of the PR and between fa31b66bbb2ae5234205a8628a78e038d917202f and a32e316cd1e1150d21a4e218c3d883e9af3d1e32.
Files selected for processing: 2-
packages/shared/src/paletteSearch.test.tspackages/shared/src/paletteSearch.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
Walkthrough
-
findMessageTokencan stop at the first whole-word match.messageMatcherenables this behavior for single-token searches and retains best-quality position collection for multi-token searches. New tests cover matching cases and accent-folded source-text offsets.Changes: Palette search matching
Layer / File(s) Summary Single-token match selection and tests
packages/shared/src/paletteSearch.ts,packages/shared/src/paletteSearch.test.tsfindMessageTokencan return after a whole-word match.messageMatcherenables this for single-token searches, including accent-folded fallback, while multi-token searches continue collecting best-quality positions. Tests cover match selection, text cases, and source-text offsets after accent folding.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Refactor
Suggested labels:
size:SSuggested reviewers:
t3dotgg
Merge Risk:
Minimal · up toa32e3-
Single-token search is optimized; no merge-blocking risk is established.
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check The description clearly explains the problem, implementation, performance measurements, tests, and scope. However, it omits the required Scope and approval section and does not provide a triaged issue… Add a Scope and approval section. Link the triaged issue or approval discussion with the relevant maintainer comment, or explain why this focused fix qualifies for an exemption. Add a dedicated Verification heading for the reported tests an… Passed checks: 3 passed-
Check name Status Explanation Title check The title is concise, uses the conventional commit format, and clearly describes the main single-token message-search optimization. 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.
Full details: Description check
-
Explanation
The description clearly explains the problem, implementation, performance measurements, tests, and scope. However, it omits the required Scope and approval section and does not provide a triaged issue, explicit maintainer approval, or a focused-fix exemption rationale.
Resolution
Add a Scope and approval section. Link the triaged issue or approval discussion with the relevant maintainer comment, or explain why this focused fix qualifies for an exemption. Add a dedicated Verification heading for the reported tests and observed results if required by the repository template.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Action not completed
-
Already reviewed the last commit. Use
@coderabbitai full reviewto rerun a review of the entire changeset.Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
-
@maria-rcks could you review the single-token early-exit rule, particularly raw/folded preference and earliest offset preservation? The latest head has green runnable CI, no unresolved CodeRabbit findings, and more than 15 minutes without a new real finding. Focused tests and a fresh batch of three independent Codex reviews passed before commit. Benchmark code is local-only and absent from the final diff; workload limits are in the PR description.
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
verified unchanged head
a32e316cd1e1150d21a4e218c3d883e9af3d1e32on linux using the repository's playwright dependency,/usr/bin/google-chrome, the real dev web client, and codexgpt-6.1-solthrough the local proxy. no source changes were needed.first ran
github/mainat71646e031ain a separate worktree. created the project, two conversations, and completed provider turns through the app. a sidebar search of a 32 kb message containing 6,400 repeatedmodewords visited 6,406 occurrences. after stopping main, copied this task's isolated app-created state and started the exact pr head. a non-pausing inspector counter on the live server's matcher loop counted 2 visits for that same message: the initial prefix, then the first whole word. this proves the early exit on the real search path; it is not a whole-app latency benchmark.nine sidebar searches returned byte-identical match arrays between main and the pr, including snippets, quality, source, hit counts, message ids, and ordering:
mode,cafe,resume,same same,vp run dev,gannet's,部署, a missing term, and a control term. this covers raw-versus-accent-folded preference, repeated words, multi-token phrases, cjk, and empty results.a fresh real codex turn on the pr generated
saffronlighthouse İ Café Café. both sidebar search and ctrl+k found the assistant message. selecting the result opened the correct conversation and highlighted the word with a 1/1 find count.blacksmith checks passed: 60/60 focused matcher and sqlite search tests;
vp run check:changed fa31b66bbb2ae5234205a8628a78e038d917202fpassed format, lint, knip, affected typechecks, and 35/35 selected tests. the runner initially lacked merge-base history; fetching the pr at depth 2 resolved that setup issue.

Not verified#
native desktop, ios/android, other providers, relay/tunnel connections, production-sized history, and the description's timing/allocation multipliers. the shared search path was exercised through linux web. this is a computation change, so before/after appearance is expected to match.
the copied task state came from newer main and contained migration 77, unknown to this pr build (76). the server warned and started without changing migration history; all live searches and the fresh pr provider turn succeeded. no upgrade/downgrade compatibility claim is made.
maria-rcks merged thisacad1d5
maria-rcks closed this
Sign in to join this conversation.
@coderabbitai review