[No-QA] chore: [Performance] Optimize useFilterFormValues (~16ms per render)#83746
[No-QA] chore: [Performance] Optimize useFilterFormValues (~16ms per render)#83746TaduJR wants to merge 12 commits intoExpensify:mainfrom
Conversation
|
@jayeshmangwani 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] |
|
@TaduJR can you provide measurements on the performance improvement please? |
|
We also have several lint issues on SearchPage. A lot of that logic was removed already |
Sure.
Hmm I think they are occurring after merging with main. Let me check |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b28ed1fb66
ℹ️ 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".
|
@TaduJR let's resolve conflicts and mark the PR as ready for review please |
…rmance-OptimizeuseFilterFormValues-16ms-per-render # Conflicts: # src/components/Search/SearchPageHeader/SearchFiltersBar.tsx
…rmance-OptimizeuseFilterFormValues-16ms-per-render
|
|
All good @luacmartins? |
|
@TaduJR can you provide additional metrics for the actual time it takes to run the hook now? |
|
@jayeshmangwani please prioritize this review when you're online |
Sure @luacmartins. I will provide today. |
…rmance-OptimizeuseFilterFormValues-16ms-per-render
…AndKeys with algorithmic improvements
…QueryJSONOrThrow helper
…s before filter loop
buildFilterFormValuesFromQuery — Algorithmic Optimization
Render Count — Selectors Prevent Re-renders
|
|
Hi @luacmartins , sorry for the delay. I won’t be able to review this PR today, but I can check it tomorrow if it’s not urgent. If it is urgent, I can ask in the C+ channel to reassign it in case someone wants to take it. |
|
Asked for a reassingment |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
| }; | ||
|
|
||
| export default useFilterFormValues; | ||
| export {policiesSelector, reportsSelector, policyCategoriesSelector, policyTagsSelector}; |
There was a problem hiding this comment.
| export {policiesSelector, reportsSelector, policyCategoriesSelector, policyTagsSelector}; |
Do we really need to export?
There was a problem hiding this comment.
I assume this is for the tests
| if (!category) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
| if (!category) { | |
| continue; | |
| } |
I think we don't need this check and same for tag too as it won't be undefined as per the type
@TaduJR Aren't we implementing the suggested change in your proposal of using |
Explanation of Change
useFilterFormValueswas called in bothSearchPageandSearchFiltersBar, creating 12 Onyx collection subscriptions (6 each) and runningbuildFilterFormValuesFromQuerytwice per render. This PR:Removes the duplicate hook call from
SearchPage— keeps it only inSearchFiltersBar, which is the sole consumer. TheuseEffectthat syncsupdateAdvancedFiltersmoves there too.Adds Onyx selectors to the 4 collection subscriptions in
useFilterFormValues— each selector extracts only the fields thatbuildFilterFormValuesFromQueryactually reads:COLLECTION.POLICY→ onlytaxRates(stripsemployeeList,customUnits, etc.)COLLECTION.REPORT→ onlyreportIDCOLLECTION.POLICY_CATEGORIES→ onlynameper categoryCOLLECTION.POLICY_TAGS→ onlynameper tagThis makes Onyx's
deepEqualcompare small selector output instead of full collection objects on every update.Fixed Issues
$ #82421
PROPOSAL: #82421 (comment)
Tests
Offline tests
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari