chore: [Performance] Optimize useAdvancedSearchFilters (~18ms per render)#84505
Conversation
|
@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] |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@aimane-chnaif please prioritize reviewing this PR when you're online! |
|
reviewing today |
|
@TaduJR conflicts |
…rmance-Optimize-useAdvancedSearchFilters-18msper-render # Conflicts: # src/hooks/useAdvancedSearchFilters.ts
|
No product review needed |
|
All yours @aimane-chnaif |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariScreen.Recording.2026-03-11.at.5.21.31.pm.mov |
|
@TaduJR We should have Tests steps to confirm our changes don't introduce any bugs. |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
Ok |
|
@TaduJR how's test cases going? |
Good, @aimane-chnaif I will finish all by EOD |
…rmance-Optimize-useAdvancedSearchFilters-18msper-render
Done @aimane-chnaif |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
|
🚧 @luacmartins has triggered a test Expensify/App build. You can view the workflow run here. |
…mize-useAdvancedSearchFilters-18msper-render chore: [Performance] Optimize useAdvancedSearchFilters (~18ms per render)
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/luacmartins in version: 9.3.36-0 🚀
|
|
🚀 Deployed to production by https://github.com/luacmartins in version: 9.3.36-10 🚀
|
Explanation of Change
The
useAdvancedSearchFiltershook was running 7 separateObject.values(policies)iterations inline per render without selector cachingStructural optimizations (Onyx selectors prevent re-renders):
policyDerivedSelector: ReplacesisFeatureEnabledInPolicies(4 calls), the report field check, the non-personal policy filter, and the tax rate existence check with a single pass over policies with early-exitflags. Returns only primitives so Onyx's
deepEqualcomparison is trivially cheap, preventing re-renders when policy data changes but derived values don't.taxRatesSelector: CachesgetAllTaxRates()result via Onyx'sdeepEqual, avoiding inline recomputation every render.hasTagsSelector: Returns a boolean with early exit on first tag found, replacing the.filter().map(getTagNamesFromTagsLists).flat()chain.availablePolicyCategoriesSelector: Uses.some()instead of.filter().length > 0for category existence checks.filterCardsHiddenFromSearch: Moved from inline call to Onyx selector parameter, enablingdeepEqualcaching at the subscription level.Consumer deduplication:
AdvancedSearchFilters.tsxhad duplicatePOLICYandCARD_LISTOnyx subscriptions (both in the hook and the consumer). Removed duplicates the hook now returnstaxRates,searchCards, andpoliciesdirectly.Algorithmic improvements:
nonPersonalPolicyCategoryIdsarray + Set allocation →hasNonPersonalPoliciesboolean flag + direct O(1) policy lookup per category keygetAllTaxRatesinline every render →hasAnyTaxRatesboolean check in single pass +taxRatesSelectorcached viadeepEqual.filter().length > 0→.some()(2 instances)Performance (Reassure, 50K policies):
main(baseline)Fixed Issues
$ #82423
PROPOSAL: #82423 (comment)
Tests
Offline tests
Same as tests
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
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-03-11.at.11.46.04.in.the.morning.mov
Android: mWeb Chrome
iOS: Native
iOS-Native.mp4
iOS: mWeb Safari
iOS-Safari.mp4
MacOS: Chrome / Safari
Mac-Chrome.mp4