App icon indicating copy to clipboard operation
App copied to clipboard

[Performance] useOnyx doesn't return new data if the selector changes but the data in the store is the same

Open pac-guerreiro opened this issue 1 year ago โ€ข 28 comments

If you havenโ€™t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


What performance issue do we need to solve?

Inefficient React component rendering when onyx collection data is updated, although we're only accessing unmodified entries of the onyx collection.

Example case: https://github.com/Expensify/App/pull/49919#pullrequestreview-2346813622

What is the impact of this on end-users?

App performance can degrade with the inefficient rendering

List any benchmarks that show the severity of the issue

N/A

Proposed solution (if any)

Mimic dependency array from some React hooks, like useEffect, to force useOnyx to fetch data if any dependency changes.

Something like useOnyx(key, options, [dependencyA]).

List any benchmarks after implementing the changes to show impacts of the proposed solution (if any)

N/A

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • [x] Android: Native
  • [x] Android: mWeb Chrome
  • [x] iOS: Native
  • [x] iOS: mWeb Safari
  • [x] MacOS: Chrome / Safari
  • [x] MacOS: Desktop

Version Number: v9.0.62-4 Reproducible in staging?: yes Reproducible in production?: yes Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos: https://github.com/Expensify/App/pull/49919#pullrequestreview-2346813622 Expensify/Expensify Issue URL: Issue reported by: Slack conversation:

View all open jobs on Upwork

Issue OwnerCurrent Issue Owner: @pac-guerreiro

pac-guerreiro avatar Nov 14 '24 20:11 pac-guerreiro

Auto-assigning issues to engineers is no longer supported. If you think this issue should receive engineering attention, please raise it in #whatsnext.

melvin-bot[bot] avatar Nov 14 '24 20:11 melvin-bot[bot]

@mountiny can you make this issue internal? @fabioh8010 and I are working on it

pac-guerreiro avatar Nov 14 '24 20:11 pac-guerreiro

You tagged the wrong person @pac-guerreiro , it's @mountiny ๐Ÿ˜„

fabioh8010 avatar Nov 14 '24 20:11 fabioh8010

Ups, sorry! ๐Ÿ˜…

pac-guerreiro avatar Nov 14 '24 20:11 pac-guerreiro

Sounds good

mountiny avatar Nov 14 '24 21:11 mountiny

Last friday I didn't work on this but tomorrow I'll open a draft PR with a possible solution

pac-guerreiro avatar Nov 17 '24 22:11 pac-guerreiro

I opened a draft PR with a possible solution for this issue - https://github.com/Expensify/react-native-onyx/pull/599

If you all agree, I can also create an eslint rule to enforce the usage of the dependency array when developers pass variables in useOnyx selector. To achieve it, I'll need to adapt this and create an additional PR to add this new rule to https://github.com/Expensify/eslint-config-expensify

pac-guerreiro avatar Nov 18 '24 20:11 pac-guerreiro

I'm waiting on @fabioh8010 feedback on this since he has an alternate solution

pac-guerreiro avatar Nov 19 '24 23:11 pac-guerreiro

We are currently discussing the issue internally.

fabioh8010 avatar Nov 20 '24 15:11 fabioh8010

Today @fabioh8010 and I discussed this issue internally. There are some ideas on the table on how to tackle this issue, so we'll continue discussing them tomorrow!

pac-guerreiro avatar Nov 20 '24 18:11 pac-guerreiro

Today @fabioh8010 continued our discussion, we are still trying to find a proper solution for this issue.

pac-guerreiro avatar Nov 22 '24 00:11 pac-guerreiro

Today I tried more possible solutions and discussed them with @fabioh8010. I've been having problems with infinite loops on getSnapshot. On Monday I'm going to discuss an alternative idea of @fabioh8010 for this performance issue.

pac-guerreiro avatar Nov 23 '24 01:11 pac-guerreiro

@fabioh8010, @mountiny, @pac-guerreiro Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Nov 26 '24 09:11 melvin-bot[bot]

Yesterday I was able to provide a possible solution to the problem and created a draft PR - https://github.com/Expensify/react-native-onyx/pull/601

@fabioh8010 provided a solution of his, which I didn't have the time to check yesterday but today I'll do it!

pac-guerreiro avatar Nov 26 '24 13:11 pac-guerreiro

Today I reviewed @fabioh8010 solution and we discussed it. We need to confirm which one is the best and how we should proceed next

pac-guerreiro avatar Nov 27 '24 00:11 pac-guerreiro

Taking this issue over Pedro since he's going to be OOO until December 12th

fabioh8010 avatar Nov 28 '24 15:11 fabioh8010

@fabioh8010, @mountiny, @pac-guerreiro Eep! 4 days overdue now. Issues have feelings too...

melvin-bot[bot] avatar Dec 02 '24 09:12 melvin-bot[bot]

Update: We agreed to test my solution against E/App and if everything is ok, we will proceed with it.

fabioh8010 avatar Dec 02 '24 22:12 fabioh8010

@fabioh8010, @mountiny, @pac-guerreiro 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

melvin-bot[bot] avatar Dec 04 '24 09:12 melvin-bot[bot]

Created a WIP Draft PR, testing the solution against E/App.

fabioh8010 avatar Dec 04 '24 22:12 fabioh8010

Update: PR opened to review!

cc @mountiny

fabioh8010 avatar Dec 05 '24 22:12 fabioh8010

@fabioh8010, @mountiny, @pac-guerreiro Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

melvin-bot[bot] avatar Dec 06 '24 09:12 melvin-bot[bot]

Update: Onyx PR was merged! I will proceed with the Onyx bump PR

fabioh8010 avatar Dec 06 '24 15:12 fabioh8010

@mountiny Could you take a quick ๐Ÿ‘€ in this PR? Onyx main is currently broken and we need that fix before proceeding with the Bump PR. Thanks!

fabioh8010 avatar Dec 09 '24 10:12 fabioh8010

Merged

mountiny avatar Dec 09 '24 11:12 mountiny

@fabioh8010, @mountiny, @pac-guerreiro 12 days overdue. Walking. Toward. The. Light...

melvin-bot[bot] avatar Dec 10 '24 09:12 melvin-bot[bot]

Will open the Bump PR today

fabioh8010 avatar Dec 10 '24 09:12 fabioh8010

Bump PR created -> https://github.com/Expensify/App/pull/53890

fabioh8010 avatar Dec 10 '24 22:12 fabioh8010

Reviewing label has been removed, please complete the "BugZero Checklist".

melvin-bot[bot] avatar Dec 18 '24 13:12 melvin-bot[bot]

The solution for this issue has been :rocket: deployed to production :rocket: in version 9.0.76-12 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:

  • https://github.com/Expensify/App/pull/53890

If no regressions arise, payment will be issued on 2024-12-25. :confetti_ball:

For reference, here are some details about the assignees on this issue:

  • @fabioh8010 does not require payment (Contractor)
  • @pac-guerreiro does not require payment (Contractor)

melvin-bot[bot] avatar Dec 18 '24 13:12 melvin-bot[bot]