Speed up SearchRouter open on large accounts#95378
Draft
sumo-slonik wants to merge 4 commits into
Draft
Conversation
Two changes to the SearchRouter empty-query open path (ManualOpenSearchRouter / SearchRouter.ListRender span): 1. Cache createFilteredOptionList results in a module-level single-entry cache keyed on input references, so reopening the router reuses the previous result while the underlying Onyx data is unchanged. Two inputs are reference-stabilized to make hits possible: usePrivateIsArchivedMap (module cache keyed on the REPORT_NAME_VALUE_PAIRS collection reference) and the visibleReportActionsData default (shared constant instead of a fresh object per call). 2. New deferContactsUntilSearch option (enabled only for the SearchRouter's SearchAutocompleteList) skips building an option per personal detail while the query is empty; the empty state shows no standalone contacts, and typing flips isSearching which builds the full set. Other useFilteredOptions consumers are unaffected (default false). Measured on web dev with 19k personal details / 588 reports: warm reopen median 199.5ms -> ~105ms, cold open 211ms -> ~150ms.
# Conflicts: # src/hooks/usePrivateIsArchivedMap.ts # src/libs/OptionsListUtils/index.ts
Option building translates strings imperatively (translateLocal), so a locale change alters the output without changing any input reference. Keying the cache on IntlStore.getCurrentLocale() makes the cached result re-localize, which the OptionsListUtils localization test guards.
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
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.
Explanation of Change
On the Sentry "P90 vital metrics - large accounts" dashboard,
ManualOpenSearchRouterroughly doubled, reaching ~1s p90 in production — nearly all of it inSearchRouter.ListRender(building the initial, empty-query option list). Profiling on a large account showed two structural issues:createFilteredOptionListis rebuilt from scratch on every open — no caching between openings, and two unstable input references made memoization impossible.Both costs grow linearly with account size, so the regression hits the largest accounts hardest.
Fix
createFilteredOptionListkeyed on input references (plus reference-stabilizedusePrivateIsArchivedMapandvisibleReportActionsDatadefault) — reopening reuses the previous result while Onyx data is unchanged.deferContactsUntilSearchoption, enabled only for the SearchRouter'sSearchAutocompleteList— skips per-contact options while the query is empty; typing flipsisSearchingand builds the full set. OtheruseFilteredOptionsconsumers keep the default (false) and are unaffected.Performance results
Measured locally on web dev with a large-account dataset: 19,161 personal details / 588 reports (span:
SearchRouter.ListRender— opening the Search Router with an empty query, the same metric tracked on the Sentry "P90 vital metrics - large accounts" dashboard).█████████████████████░211 ms████████████████████░░199.5 ms███████████████░░░░░░░~150 ms██████████░░░░░░░░░░░░~105 msFixed Issues
$
PROPOSAL:
Tests
from:followed by a few letters of a contact's name — verify the autocomplete suggests matching contacts.Offline tests
Unnecessary — this PR only changes how the Search Router option list is built (caching + skipping unused work); it does not touch any network or persistence logic.
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, 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.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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari