Skip to content

Improve conversation message search responsiveness [WPB-26110] - #21623

Merged
screendriver merged 3 commits into
devfrom
mo/debounce-conversation-message-search
Jun 24, 2026
Merged

Improve conversation message search responsiveness [WPB-26110]#21623
screendriver merged 3 commits into
devfrom
mo/debounce-conversation-message-search

Conversation

@MohamadJaara

@MohamadJaara MohamadJaara commented Jun 22, 2026

Copy link
Copy Markdown
Member
BugWPB-26110 Very slow searching in a conversation

Summary

Improves in-conversation message search responsiveness in the browser.

The search input now debounces queries, avoids stacking multiple expensive searches while the user is still typing, and keeps the browser responsive while scanning large local conversation histories.

Why It Was Slow

Conversation message search was doing more work than it looked like from the UI:

  • Every query loaded all text/link-ish events for the conversation from local storage.
  • The app scanned those events in JavaScript on the browser main thread.
  • Each event extracted searchable text from multiple message shapes before matching.
  • The previous search helper rebuilt the same search regex for every single message.
  • If the user kept typing while a search was still running, more full scans could queue up behind the active one.

That means searching a large conversation was not just N string checks. It could become repeated local storage reads, repeated message-text extraction, repeated regex compilation, and repeated main-thread scans.

Fixes

  • Increased full message search debounce to 500ms.
  • Coalesced in-flight searches so only one search runs at a time.
  • Kept only the latest pending query while a search is already running.
  • Ignored stale search results when the input has moved on.
  • Batched local event scanning and yielded between batches so the browser can keep rendering/responding.
  • Compiled the search regex once per query instead of once per message.
  • Reset the reused global regex before each event match to avoid skipping consecutive results.

Tests

  • Added coverage for debounce timing and in-flight search coalescing.
  • Added coverage for reused regex matching consecutive events without skipping results.

Verification

  • yarn nx test webapp --testFile=apps/webapp/src/script/page/MainContent/panels/Collection/Collection.test.tsx --runInBand
  • yarn nx test webapp --testFile=apps/webapp/src/script/repositories/conversation/ConversationService.test.ts --runInBand
  • yarn nx run webapp:type-check

@MohamadJaara
MohamadJaara force-pushed the mo/debounce-conversation-message-search branch from 7ddf561 to 1a1db66 Compare June 22, 2026 15:16
@MohamadJaara
MohamadJaara marked this pull request as ready for review June 22, 2026 15:16
@MohamadJaara MohamadJaara changed the title Improve conversation message search responsiveness Improve conversation message search responsiveness [WPB-26110] Jun 22, 2026
@screendriver
screendriver force-pushed the mo/debounce-conversation-message-search branch 4 times, most recently from b4ff66b to a980701 Compare June 24, 2026 08:14
screendriver
screendriver previously approved these changes Jun 24, 2026
@screendriver
screendriver enabled auto-merge June 24, 2026 08:17
Extract full-search query lifecycle management into useFullSearch so input state, immediate parent updates, debounced provider execution, stale result handling, and cancellation are explicit and separated from rendering.

Thread AbortSignal through the collection search path and check cancellation at conversation search batch boundaries. Extract conversation event matching into a named helper while preserving regex reuse, lastIndex reset, expired ephemeral event filtering, and whitespace-query short-circuiting.

Add debounce-fn to @wireapp/webapp and keep use-debounce available for existing callers. Add regression coverage for debounce timing, immediate change notification, clearing results, stale result suppression, latest-query behavior, regex reuse, expired events, whitespace queries, and batch-boundary aborts.
@screendriver
screendriver force-pushed the mo/debounce-conversation-message-search branch from a980701 to e57b8f0 Compare June 24, 2026 08:35
@screendriver
screendriver added this pull request to the merge queue Jun 24, 2026
Merged via the queue into dev with commit 9c748d8 Jun 24, 2026
12 checks passed
@screendriver
screendriver deleted the mo/debounce-conversation-message-search branch June 24, 2026 09:09
@sonarqubecloud

Copy link
Copy Markdown

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