Skip to content

[PERF] Eliminate redundant Todos computations by using Onyx derived values #81353

@mountiny

Description

@mountiny

Background

Todos are computed by analyzing all expense reports in a user's account, iterating through potentially thousands of reports and transactions to determine eligibility. This data is consumed by multiple components with different requirements:

  • SearchContext needs the full todos data structure, including all reports, transactions, policies, and related data formatted as search results
  • Other components only require simple report counts

Problem

When multiple components need todos-related state on large accounts, if each consumer triggers heavyweight todos computation independently, then render time increases and user-perceived performance degrades.

Solution

Move reusable categorization logic (categorizing reports into submit/approve/pay/export buckets) from the useTodos hook into an Onyx derived value at ONYXKEYS.DERIVED.TODOS. This derived value would compute only the categorized report arrays and transaction mappings at the Onyx level. Components can then use selectors to extract just the report counts from the derived value, avoiding the heavy search results data construction entirely. The useTodos hook would subscribe to this derived value and build the full search results data structure only when required by SearchContext, ensuring the expensive computation runs fewer times.

Results

Tested on iOS exfy-perf heavy account when opening multiple reports in Reports Tab:

Metric Before After Improvement
ManualNavigateToInboxTab span 1.66s 1.23s 26% reduction
useSearchTypeMenuSections total time 700ms 65ms ~91% reduction
openReport span 1.72s 1.49s 8-13% reduction (~200ms depending on report context)
useTodos total time 350ms 9ms ~97% reduction
buildSearchResults total time 53ms 8ms ~85% reduction

Proposal

Slack discussion: https://expensify.slack.com/archives/C05LX9D6E07/p1770106608149389

Issue OwnerCurrent Issue Owner: @LukasMod

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.ReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

Status

CRITICAL

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions