Skip to content

perf(notes): debounce live search + score the query once, not per keystroke - #330

Merged
SMK1705 merged 1 commit into
mainfrom
perf/notes-search-debounce
Jul 28, 2026
Merged

perf(notes): debounce live search + score the query once, not per keystroke#330
SMK1705 merged 1 commit into
mainfrom
perf/notes-search-debounce

Conversation

@SMK1705

@SMK1705 SMK1705 commented Jul 28, 2026

Copy link
Copy Markdown
Owner

…e/emission

Notes search runs live as you type, and each pass calls SemanticIndex.scores() — which
embeds the query, loads every stored vector, recomputes the corpus centroid and mean-
centres them all. With the neural embedder on (#329) the embed is a MediaPipe inference,
so typing "kitchen sink tap" fired ~16 full semantic passes back to back. That's the jank.

Two fixes, both behaviour-preserving:

- Debounce the typed query (~220ms) before the search runs, so a keystroke storm settles
  into ONE pass. Only the query is debounced — filter toggles and a blank query (clearing
  search / first load) stay instant, so nothing the user expects to be immediate is delayed.

- Hoist scores() out of the per-emission map. It was called inside `base.map { ... }`, so a
  background note write re-ran it and re-embedded the query even though the query hadn't
  changed. The scores depend only on the query and the embeddings table, not the note list,
  so it's now computed once per query and the map just re-ranks with the cached scores
  (rankBySearch -> rankWith, embedding removed).

Net: from ~one neural inference + full-vector load PER KEYSTROKE (and again on every note
change) to one per settled query. Results are identical — the full unit suite (incl.
NotesViewModelTest / NotesScreenTest search cases) stays green.
@SMK1705
SMK1705 merged commit b2329ba into main Jul 28, 2026
1 check passed
@SMK1705
SMK1705 deleted the perf/notes-search-debounce branch July 28, 2026 19:10
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.

1 participant