Skip to content

[$250] [Due for payment 2025-07-14] Use indexed object structure for OnyxCache #64950

@mountiny

Description

@mountiny

Coming from here

Background

react-native-onyx is using its internal cache mechanism to get value from cache while first connection to Onyx is being made through useOnyx so the cached value can be returned immediately.

Problem

When useOnyx requests collection data from cache while the first connection to Onyx is being made, the implementation loops through all cached keys to find matching items, which causes response times to degrade linearly with cache size, which prevents large accounts from achieving acceptable performance in multiple flows of the app.

Solution

Change the shape of the Onyx cache to store collections as indexed objects instead of flat key-value pairs. When requesting collection data, the useOnyx should directly access the pre-organized collection object instead of iterating through thousands of keys. This transforms collection access from O(n) complexity to O(1), delivering instant retrieval regardless of cache size.
Some numbers from account with 42k cached Onyx keys:

  • iOS Simulator: time spent on getting values from cache on app start: 1.4s → 23ms
  • iOS Simulator: time spent on getting values from cache on opening Expense chat: 1s → 18ms
  • Android emulator: app launch 5s → 3s
    Thanks to that useOnyx times go down as well - on opening Expense chat total time dropped from ~650ms to ~170ms
Issue OwnerCurrent Issue Owner: @
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021942727528896232627
  • Upwork Job ID: 1942727528896232627
  • Last Price Increase: 2025-07-15

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions