Skip to content

[Perf] Avoid extra rerenders on Spend tab (SearchTypeMenuWide) #97201

Description

@cristipaval

Problem

While working on Send a Message performance, @LukasMod noticed extra rerenders on the Spend tab, specifically in the SearchTypeMenuWide sections.

The root cause is in useTodoCounts. It subscribes to several large Onyx collections (REPORT, POLICY, TRANSACTION, REPORT_ACTIONS, REPORT_METADATA), so it re-runs on every write to any of them, even writes that don't change any to-do count (like renaming a chat or receiving a message). On each re-run it returned a new {counts, singleReportIDs} object, so memoized consumers like SearchTypeMenuWide saw a new reference and re-rendered on unrelated Onyx traffic.

Fix

PR: #97109

When no count and no single-report ID changed, return the previously stored object (frozen) so the reference stays stable and memoized children skip the rerender. When something does change, behavior is unchanged. Includes a regression test for both the stable and changed-reference cases.

Files:

  • src/hooks/useTodoCounts.ts
  • tests/unit/useTodoCountsTest.tsx

Related

Parent metric: #77176 ([Metrics] Improve ManualSendMessage)

Issue OwnerCurrent Issue Owner: @LukasMod

Metadata

Metadata

Labels

ImprovementItem broken or needs improvement.ReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions