Skip to content

[Onyx Audit] useOnyx is expensive (especially on list items) #71202

@fabioh8010

Description

@fabioh8010

Overview

This issue is part of our current effort to audit the performance and scalability of Onyx.

During the Step 1: Objective Analysis we gathered a list of Perceived Problems we have exclusively about Onyx, that is, the problems in Onyx we imagine or have some evidences that that are pain points / performance bottenecks to Onyx, but we need more analysis to confirm if they really are and, if so, how much of a problem they are currently.

The main goal right now is to deep dive into each Perceived Problem, investigate/audit it and come up with findings, which we will use for the next discussions.

Problem

There are performance improvements every time we decide to remove useOnyx calls from list items and/or lift up the state. Here are some proposals/discussions that show this:

While these kind of solutions make our App faster, they also end up not addressing the root cause of the issue: useOnyx calls are too expensive to be used inside list items.

useOnyx should be extremely fast to the point we can just pass entity IDs to our components and use them to hook into Onyx state, without having a performance hit. Removing useOnyx and lifting up the state solves the problem temporarily but it will continue to limit our application and nudge us into worse code and bad practices.

I think Rory's proposal it's the right direction for this topic: Audit useOnyx and determine why it's expensive to call on list items.

We have been working on several improvements on useOnyx e.g. selector memoization and getSnapshot caching that will greatly benefit this part, but looks like there are still more we can do about this.

Action Items

  1. Audit useOnyx and determine why it's expensive to call on list items.
  2. Furthermore, audit useOnyx to check if we have more performance bottlenecks there, not exclusively related to list items.

Relevant Links

Step 1 Canvas: https://expensify.slack.com/docs/T02P6RS2ZK7/F09B668M1MG

Slack thread: https://expensify.slack.com/archives/C05LX9D6E07/p1757416459028329

Metadata

Metadata

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions