-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Coming from: https://expensify.slack.com/archives/C05LX9D6E07/p1747410805866429
Background
When createOnyxProvider was first added, it came with a big performance boost; when we had many identical withOnyx calls on components that were rendered many times, then any time the Onyx data changed, we had to do N callbacks to update all the subscribers, which led to N setState calls and N independent re-renders. This was inefficient and jammed up React. By creating a central subscriber and propagating state updates throughout the app using the Context API, things became more performant.
However, things have changed since then:
- We have the OnyxConnectionManager that ensures multiples useOnyx reuse the same subscription when connecting to the same key. However, each of the subscriber callbacks are still executed, so it's unclear if this is functionally the same as having a single subscriber, then propagating changes with the Context API, or if there's a still a performance difference.
- We use hooks instead of HOCs now, and
useOnyxusesuseSyncExternalStorewhich is, in terms of performance and state updates, more suited to integrating with external stores (like Onyx) thansetStatewas - React has built-in render batching now too, which wasn't present when
createOnyxProviderwas added
Problem
When we have multiple similar methods to manage state without clear guidelines on when to use which, it leads to developer and reviewer overhead. The code may be more complex than it needs to be, but it generally seems like nobody knows whether that's true or not.
Solution
Investigate the performance impact of createOnyxProvider v.s. just directly using useOnyx. Report back so that we can decide on next steps:
- Do nothing, OR
- Document the result and provide guidance on when
createOnyxProvidershould be used and when it should not, OR - Investigate if we can build the performance optimization of
createOnyxProviderglobally into react-native-onyx, OR - Remove
createOnyxProviderif it's not serving any purpose anymore
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~021948296472514036129
- Upwork Job ID: 1948296472514036129
- Last Price Increase: 2025-07-24
Issue Owner
Current Issue Owner: @Issue Owner
Current Issue Owner: @twisterdotcomMetadata
Metadata
Labels
Type
Projects
Status