Skip to content

[Due for payment 2025-08-11] [Due for payment 2025-08-05] [$250] [Due for payment 2025-07-25] Investigate createOnyxProvider performance #62300

@roryabraham

Description

@roryabraham

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 useOnyx uses useSyncExternalStore which is, in terms of performance and state updates, more suited to integrating with external stores (like Onyx) than setState was
  • React has built-in render batching now too, which wasn't present when createOnyxProvider was 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 createOnyxProvider should be used and when it should not, OR
  • Investigate if we can build the performance optimization of createOnyxProvider globally into react-native-onyx, OR
  • Remove createOnyxProvider if 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 OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @twisterdotcom

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions