Skip to content

[Due for payment 2026-03-19] [$250] [Performance] Optimize useAdvancedSearchFilters (~18ms per render) #82423

Closed

Description

@luacmartins

Problem

useAdvancedSearchFilters takes ~18ms per render and contributes to slow Reports page navigation.

Solution

Optimize the hook (e.g. memoization, reducing work per render, or moving work off the critical path). Use React Profiler / Chrome DevTools to validate improvements.

Issue OwnerCurrent Issue Owner: @mallenexpensify
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022024628964028802674
  • Upwork Job ID: 2024628964028802674
  • Last Price Increase: 2026-03-02
  • Automatic offers:
    • aimane-chnaif | Reviewer | 110690987

Activity

  1. self-assigned this
    on Feb 13, 2026
  2. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Feb 13, 2026
  3. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 19, 2026
  4. melvin-bot commented on Feb 19, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @aimane-chnaif (External)

  5. changed the title [-][Performance] Optimize useAdvancedSearchFilters (~18ms per render)[/-] [+][$250] [Performance] Optimize useAdvancedSearchFilters (~18ms per render)[/+] on Feb 19, 2026
  6. melvin-bot commented on Feb 19, 2026

    @melvin-bot
  7. mas7 commented on Feb 21, 2026

    @mas7

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    `useAdvancedSearchFilters` runs ~18ms of computation on every render due to multiple unmemoized expensive operations across Onyx collections.

    What is the root cause of that problem?

    The hook performs six expensive computations on every render with no memoization:

    1. `getAllTaxRates(policies)` — iterates all policies to collect tax rates
    2. `getAllPolicyValues(policyID, ...)` — called twice, scans policy collections
    3. `tagListsUnpacked` — chains `.filter().map().flat()` across all policy tag lists
    4. `nonPersonalPolicyCategoryCount` — builds a `new Set()` and filters every render
    5. `shouldDisplayReportFieldFilter` — iterates all policies and their `fieldList`
    6. `useWorkspaceList()` returns a new object reference every render

    The hook subscribes to multiple Onyx stores, so any store update triggers a re-render that re-runs all six computations from scratch even when the relevant inputs haven't changed.

    What changes do you think we should make in order to solve the problem?

    Wrap each expensive computation in `useMemo` with targeted dependency arrays:

    1. Tax rates: `useMemo(() => getAllTaxRates(policies), [policies])` — same pattern already used in `useFilterFormValues`
    2. Policy values: Memoize both `getAllPolicyValues` calls with their respective dependencies
    3. Tag lists unpacking: `useMemo(() => policyTagsLists?.filter().map().flat(), [policyTagsLists])`
    4. Category count: `useMemo(() => { const s = new Set(...); return s.size; }, [policyCategories])`
    5. Report field filter: `useMemo(() => checkReportFieldDisplay(policies), [policies])`
    6. Workspace list stability: Extract into a stable selector or use `useRef` comparison to prevent unnecessary downstream invalidation

    Where applicable, I'll use Onyx's built-in `selector` option (the same pattern as `availablePolicyCategoriesSelector` already defined in the codebase) to push filtering closer to the data source.

    I will validate each memoization point individually with React Profiler to confirm the cumulative ~18ms reduction.

  8. yifangoh commented on Feb 22, 2026

    @yifangoh
    Contributor

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  9. github-actions commented on Feb 22, 2026

    @github-actions
    Contributor

    ⚠️ @imgyf Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  10. melvin-bot commented on Feb 23, 2026

    @melvin-bot

    @aimane-chnaif Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  11. 39 remaining items

  12. melvin-bot commented on Mar 12, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  13. mallenexpensify commented on Mar 20, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @TaduJR paid $250 via Upwork
    Contributor+: @aimane-chnaif paid $250 via Upwork

    @aimane-chnaif plz complete the BZ checklist and tag me in a post once you have. Thx

    @TaduJR can you please accept the job below? Please reply here and tag me once you have.
    https://www.upwork.com/jobs/~022035102200994135237

  14. aimane-chnaif commented on Mar 20, 2026

    @aimane-chnaif
    Contributor

    This is performance improvement so we can skip checklist

  15. TaduJR commented on Mar 21, 2026

    @TaduJR
    Contributor

    @TaduJR can you please accept the job below? Please reply here and tag me once you have.

    Offer Accepted @mallenexpensify

    Thanks!

  16. mallenexpensify commented on Mar 23, 2026

    @mallenexpensify
    Contributor

    @TaduJR paid, summary updated above.e

    Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions