perf(search): adaptive debounce and background matching for in-note search#3249
Open
MiMoHo wants to merge 1 commit into
Open
perf(search): adaptive debounce and background matching for in-note search#3249MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
…earch The in-note search started almost immediately (50/200 ms static delay) after each typed character and ran counting, occurrence lookup and span highlighting synchronously on the main thread. In long notes this freezes the UI after the very first typed letter. - The debounce delay now adapts to the measured duration of the previous search + highlight pass: clamp(2 x lastDuration, 50 ms, 750 ms), plus 150 ms for queries of up to 3 characters. Short notes keep the current snappy behavior. - Occurrence counting runs on a background executor. A generation counter cancels superseded searches, so only the newest query result is applied (as suggested in nextcloud#1729). - jumpToOccurrence no longer allocates full lower-case and substring copies of the note content per query; the recursive, case-sensitive indexOfNth got replaced by a single case-insensitive matcher pass. Fixes nextcloud#1729 Helps nextcloud#2489 Signed-off-by: MiMoHo <37556964+MiMoHo@users.noreply.github.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This was referenced Jul 2, 2026
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.
Problem
Fixes #1729. In long notes, in-note search starts searching after the very first
typed letter. Counting, nth-occurrence lookup and highlighting all ran synchronously
on the main thread, so a single-letter query with thousands of matches freezes the
UI for seconds (see the "&"-prefix workaround described in #1729).
Changes
with the measured duration of the previous search + highlight pass —
clamp(2 × lastDuration, 50 ms, 750 ms), plus 150 ms for queries ≤ 3 characters.Short notes keep the current snappy behavior (addressing the earlier concern in
Slow search in long notes #1729 that a fixed 1 s delay would hurt every use case), while long notes
automatically get a delay long enough to let the user finish typing. Measuring
real duration is more robust than scaling by content length, because the cost is
dominated by the number of matches.
background executor; a generation counter discards superseded results ("some kind
of Cancel event", as suggested by the maintainer in Slow search in long notes #1729). Only the newest query
is highlighted, on the main thread.
jumpToOccurrence()allocated a fulltoLowerCase()copy plus asubstring(0, index)copy of the entire note perquery. Replaced by a single case-insensitive
Matcherpass; the recursive,case-sensitive
indexOfNthis gone (it also disagreed with the case-insensitivecounting/highlighting).
Not covered
The remaining per-keystroke cost of the editor itself lives in
nextcloud-commons:markdown— see the companion PRstefan-niedermann/nextcloud-commons#436 (executor reuse in
EditorStateNotifier, debouncedSearchHighlightTextWatcher). BumpingcommonsVersionafter its release will address #2489 / #3162.Testing
./gradlew test).continue typing — the UI no longer freezes after the first letter; searching in a
short note behaves as before.