-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
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 Owner
Current 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
Type
Projects
Status