perf(notes): debounce live search + score the query once, not per keystroke - #330
Merged
Conversation
SMK1705
commented
Jul 28, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.