Skip to content

Stacked features 5: search optimization#416

Merged
graydawnc merged 2 commits into
paperboytm:mainfrom
AmagiDDmxh:feat/search-hot-path
Jul 15, 2026
Merged

Stacked features 5: search optimization#416
graydawnc merged 2 commits into
paperboytm:mainfrom
AmagiDDmxh:feat/search-hot-path

Conversation

@AmagiDDmxh

@AmagiDDmxh AmagiDDmxh commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Stack position

Part 5 of 7. Rebased onto main (#412#415 merged); the next PR is #417.

Why

Home-page preview search used leading-wildcard LIKE over denormalized full-session text on every keystroke, through synchronous better-sqlite3 in the Electron main process — larger indexes could block input for hundreds of milliseconds.

What changed

  • Added a production-equivalent search benchmark with p95 and maximum blocking budgets.
  • Replaced the preview hot path with FTS5 prefix queries and trigram queries for CJK.
  • Preserved title weighting, term coverage, user-message preference, filters, project identity, pins, snippets, and highlighting.
  • Kept the LIKE fallback for every plan whose terms cannot match their FTS table: short-CJK terms, any sub-trigram term when the query contains CJK (错误码 42), and punctuation-only terms under unicode61 (foo =>).
  • Gated one-code-point ascii previews; single CJK characters stay served through the LIKE path.
  • The renderer is untouched: the live typing path (CommandPalette) already issues one request per input change. An earlier revision changed a renderer path with no live callers; that change was dropped in review.

Verification

  • 500 sessions / 170k messages: p95 0.76 ms and 1.22 ms for the measured queries.
  • 750 sessions / 255k messages: p95 1.13 ms and 1.08 ms; maximum 1.24 ms.
  • Real 393.6 MB index / 489 sessions: p95 6.75 ms and 7.94 ms; maximum 9.99 ms.
  • Regression tests cover 错误码 42, foo =>, and single-CJK-char shapes at both the plan level and through searchSessionPreview.
  • Core tests: 417 passed, 1 skipped. App tests: 447 passed. Typecheck and type-aware lint clean.

Review notes

Search remains in the main process because the measured synchronous maximum is below 10 ms on the real index and below 2 ms on both synthetic fixtures. A worker thread would add lifecycle and consistency complexity without addressing a measured budget breach.

Known fast-follows (low severity, tracked in review): FTS candidates matched via diacritic folding can render an unhighlighted snippet anchored at offset 0.

@AmagiDDmxh AmagiDDmxh changed the title Stacked features 4: search optimization Stacked features 5: search optimization Jul 12, 2026
@AmagiDDmxh
AmagiDDmxh marked this pull request as draft July 13, 2026 20:48
@AmagiDDmxh
AmagiDDmxh force-pushed the feat/search-hot-path branch 3 times, most recently from f565ef5 to 3fb75a7 Compare July 15, 2026 04:59
@AmagiDDmxh
AmagiDDmxh marked this pull request as ready for review July 15, 2026 05:00
AmagiDDmxh and others added 2 commits July 15, 2026 18:41
Address review findings on the FTS preview plan:

- A trigram plan (any CJK in the query) ANDs its terms, but trigram
  phrases never match below 3 codepoints — one short term zeroed out the
  whole preview ('错误码 42', '迁移记录 v2' returned nothing). Any
  sub-trigram term now sends the query to the LIKE fallback.
- Punctuation-only terms tokenize to an empty phrase under unicode61 and
  AND-away every other term ('foo =>' returned nothing). Zero-token terms
  now send the query to the LIKE fallback.
- Single CJK characters are meaningful queries and go back to the LIKE
  path instead of being gated with ascii single chars; the pre-FTS
  behavior is restored.
- Drop the renderer request-routing changes: they modified a code path
  with no live callers (SearchBar is not rendered; the live typing path
  is CommandPalette, which already issues one request per input change).
  The perf win of this PR is entirely core-side.

Regression tests cover all three query shapes at both the plan level and
through searchSessionPreview.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@graydawnc
graydawnc force-pushed the feat/search-hot-path branch from 3fb75a7 to 1cf227f Compare July 15, 2026 10:48
@graydawnc
graydawnc added this pull request to the merge queue Jul 15, 2026
Merged via the queue into paperboytm:main with commit 94289a0 Jul 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants