Proposal: https://expensify.slack.com/archives/C05LX9D6E07/p1753279273230309
Problem
In a few components (UserSelectPopup, NewChatPage etc.) that render options list, the getValidOptions helper is used to determine which options to display. getValidOptions is called on every option manipulation by the user (e.g. adding user to filter or newly created chat) and takes quite a lot of time to process the data.
Solution
getValidOptions can be extracted into separate useMemo that is not combined with selectedOptions (dependency that changes on each interaction).
getValidOptions uses selectedOptions to set isSelected property but in case of those lists these won't be used anyways (selection state is handled on the component level, making it redundant). What we need to take care of is to remove duplicates, which is also done by the next step in data pipeline filterAndOrderOptions (or could be added with filterSelectedOptions helper which exists in the draft PR).
Alternative solution
Memoize getValidOptions itself with memoize helper. It should persist the memoization between screen transitions, making subsequent openings of affected screens quicker (as getValidOptions will hold its memoized version and just retrieve that instead of doing it once again on mount). However, it comes with tradeoff of keeping previous arguments in memory.
PR: #66938
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~021948303128396747028
- Upwork Job ID: 1948303128396747028
- Last Price Increase: 2025-07-24
Issue Owner
Current Issue Owner: @bfitzexpensify
Proposal: https://expensify.slack.com/archives/C05LX9D6E07/p1753279273230309
Problem
In a few components (UserSelectPopup, NewChatPage etc.) that render options list, the getValidOptions helper is used to determine which options to display. getValidOptions is called on every option manipulation by the user (e.g. adding user to filter or newly created chat) and takes quite a lot of time to process the data.
Solution
getValidOptions can be extracted into separate useMemo that is not combined with selectedOptions (dependency that changes on each interaction).
getValidOptions uses selectedOptions to set isSelected property but in case of those lists these won't be used anyways (selection state is handled on the component level, making it redundant). What we need to take care of is to remove duplicates, which is also done by the next step in data pipeline filterAndOrderOptions (or could be added with filterSelectedOptions helper which exists in the draft PR).
Alternative solution
Memoize getValidOptions itself with memoize helper. It should persist the memoization between screen transitions, making subsequent openings of affected screens quicker (as getValidOptions will hold its memoized version and just retrieve that instead of doing it once again on mount). However, it comes with tradeoff of keeping previous arguments in memory.
PR: #66938
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @bfitzexpensify