82307: debounce autocomplete query and memoize search options#86925
82307: debounce autocomplete query and memoize search options#86925abbasifaizan70 wants to merge 9 commits intoExpensify:mainfrom
Conversation
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
@aimane-chnaif Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4e8ba5a482
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
PR doesn’t need product input as a performance PR. Unassigning and unsubscribing myself. |
Explanation of Change
The
SearchRouterwas passingautocompleteQueryValue(updated viauseStateon every keystroke) directly toSearchAutocompleteList, triggering synchronousgetSearchOptions()+combineOrderingOfReportsAndPersonalDetails()+isSearchStringMatch()on every character typed, freezing the JS thread on mobile.Structural optimizations (debouncing + memoization prevent redundant work):
useDebouncedStateforautocompleteQueryValue: ReplacesuseStateso the expensiveSearchAutocompleteListfiltering only runs after the user pauses typing, not on every keystroke. The immediate value still drives arrow-key navigation and contextual logic.useMemoforsearchOptions: WrapsgetSearchOptions()so it only re-runs when its 13 dependencies actually change, instead of re-computing on every render.useMemoforrecentReportsOptions: WrapscombineOrderingOfReportsAndPersonalDetails()so sorting/filtering is skipped whenautocompleteQueryValueandsearchOptionshaven't changed.Algorithmic improvement:
isSearchStringMatch:new RegExp()per word per item → compile once per call, reuse across all itemsisSearchStringMatch:matchingflag withcontinuepast failures → earlyreturn falseon first mismatchsearchWords:new Set()keeping empty strings →Array.from(new Set(...)).filter(Boolean)Performance (Reassure, 40K reports):
main(baseline)getFilteredOptionswith searchfilterAndOrderOptions(40K items, 3-word query)Fixed Issues
$ #83207
PROPOSAL: #83207 (comment)
Tests
Offline tests
Same as tests.
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screen.Recording.2026-04-02.at.4.04.17.AM.mov
Android: mWeb Chrome
Screen.Recording.2026-04-02.at.4.05.33.AM.mov
iOS: Native
Screen.Recording.2026-04-02.at.3.57.50.AM.mov
iOS: mWeb Safari
Screen.Recording.2026-04-02.at.3.58.48.AM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-04-02.at.3.56.08.AM.mov