Skip to content

[Due for payment 2025-08-07] [$125] Memoize getValidOptions across components #67032

Description

@kacper-mikolajczak

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 OwnerCurrent Issue Owner: @bfitzexpensify

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2ExternalAdded to denote the issue can be worked on by a contributorNewFeatureSomething to build that is a new item.

Fields

No fields configured for Feature.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions