Repository navigation
Description
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
What performance issue do we need to solve?
e.g. memory consumption, storage read/write times, React native bridge concerns, inefficient React component rendering, etc.
- storage read/write times
- inefficient React component rendering
This component is one of the most used components and has more than 310 instances depending on chat size
The current way that the HOC works is that it will make a new Onyx connection per each withOnyx instance.
A benchmark reviewed that for a large chat the we're spending about 50sec for the Onyx.get related to retrieving the preferredLocale
What is the impact of this on end-users?
List specific user experiences that will be improved by solving this problem e.g. app boot time, time to for some interaction to complete, etc.
- app boot time
- chat switching time
List any benchmarks that show the severity of the issue
Please also provide exact steps taken to collect metrics above if any so we can independently verify the results.
I'm using Onyx.printMetrics() to monitor the Onyx.get calls that happen during init: https://github.com/Expensify/react-native-onyx#benchmarks
Results
| Device | Samsung Galaxy S7 Edge (2016) |
|---|---|
| OS | Android 8.0 |
| Total: | 123.80sec | Last | 17.49sec | ReportID | 71955477 |
|---|
| method | total time spent | max | min | avg | time last call completed | calls made |
|---|---|---|---|---|---|---|
| Onyx:get | 96.85sec | 2.92sec | 0.10ms | 144.77ms | 17.48sec | 669 |
- Full info in excel: https://docs.google.com/spreadsheets/d/1wGrVXsad6ayQZVqvyUmTuTb1cmeegdE0y-IFzhLiPKU/edit#gid=73551349&range=J8 (search for
preferredLocale)
Setup
Using this Expensify/App hash: b2582f3
Modify this file: src/Expensify.js
- For
Onyx.initaddcaptureMetrics: true - At the end of the file add
global.Onyx = Onyx;
Modify src/libs/Navigation/AppNavigator/MainDrawerNavigator.js
- Make
getInitialReportScreenParamsalways return the same report - e.g.
return {reportID: '71955477'};
Start the app and connect with Flipper or a Hermes Debugger
Steps
- Reload the app
- Wait for processes to settle (about 5-10sec after LHN loads)
- you can use
Onyx.printMetrics({ format: 'string' }})when it starts to return the same value - everything is loaded
- Run
Onyx.printMetrics({ format: 'csv', raw: true }) - Copy the results to a temp file
- Import file as new sheet in excel
Proposed solution
Extract a LocaleContextProvider that wraps the App - the implementation would be pretty much identical to how the class WithLocalize works at the moment:
App/src/components/withLocalize.js
Line 49 in ad77386
| class WithLocalize extends React.Component { |
The difference would be that it will
render a React ContextProvider componentNow only the top level component that wraps the
App subscribes to OnyxThe HOC
withLocalize changes to use a LocaleContextConsumerIt uses the context to get translation related props and pass them to the
WrappedComponentEverything else stays the same
List any benchmarks after implementing the changes to show impacts of the proposed solution (if any)
Note: These should be the same as the benchmarks collected before any changes.
I've done a quick test to verify there will be a significant reduction in Onyx.get time. It's demonstrated in the initial changes in the PR here: #4253
| Total: | 62.62sec | Last | 12.27sec | ReportID | 71955477 |
|---|
| method | total time spent | max | min | avg | time last call completed | calls made |
|---|---|---|---|---|---|---|
| Onyx:get | 40.44sec | 1.79sec | 0.08ms | 139.94ms | 12.27sec | 289 |
Platform:
Where is this issue occurring?
- Web
- iOS
- Android (Biggest impact)
- Desktop App
- Mobile Web
Version Number: 1.0.80-2
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
Expensify/Expensify Issue URL:
Activity
MelvinBot commentedon Jul 28, 2021
Triggered auto assignment to @mountiny (
Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.kidroca commentedon Jul 28, 2021
Issue created per the discussion here: #4253 (comment)
mountiny commentedon Jul 29, 2021
@kidroca 👋 Since this is a
dailyissue, can you try to drop some line here every working day to update on your progress. Either some summary of what has been done in the Draft PR (it helps to see the steps made in a bigger picture) or simply that you have not had time to work on this that given day.Thank you very much and have a great day 🙌
kidroca commentedon Jul 29, 2021
@mountiny
OK will do.
I wasn't sure I should be working on this ticket before someone officially approved it
Also ATM the ticket is not assigned to me, can you add me to the assignees?
MelvinBot commentedon Jul 29, 2021
Triggered auto assignment to @JmillsExpensify (
External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.mountiny commentedon Jul 29, 2021
@kidroca Feel free to start working on this. Performance is very important to us right now. Jason should be able to create the Upwork job for you 🙌
Let me know if you will need help with anything!
kidroca commentedon Jul 30, 2021
Thanks, I just needed the green light
Instead of creating an Upwork job I think I can just log my work for this ticket under my hourly contract
cc @arielgreen
mountiny commentedon Jul 30, 2021
@kidroca Ah, you are right, I was not aware of this. I believe that is the way to go. Is that right, Ariel? :) Thank you for confirming!
arielgreen commentedon Jul 30, 2021
Yep, @kidroca, that's perfect. Thanks.
kidroca commentedon Jul 30, 2021
I've pulled the latest changes and captured new "PRE" benchmark information.
hash: f856107
Legend
Onyx.getcallsAndroid Before
Android After
iOS Before
iOS After
Edit: Added "After" benchmarks and reordered for easier comparison
kidroca commentedon Jul 30, 2021
Added the new "After" benchmarks as well
It seems whatever recent improvements were merged to
mainthey reduced the Onyx get calls.My original benchmark on this same chat had 669
Onyx.getcalls, now they are 430 (before the proposed change).With the proposed change the calls are reduced to 297.
The "Total Time" isn't reduced as significantly as the last hash (123 -> 63) but it's still reduced (65 -> 56)
I think we're seeing the effect of the RN bridge getting "un-flooded" and so the drop in time is not as big as before
because the bridge doesn't have to delay execution
I've benchmarked
initI haven't captured how chat switch is affected. I can do another run to capture this next weekquinthar commentedon Jul 31, 2021
Out of curiosity, is this the same benchmark for iOS and Android? Is it safe to say Android is roughly 2x slower overall? What is the major cause of the 2x slowdown?
kidroca commentedon Jul 31, 2021
Yes, it's the same test for both platforms
These are physical devices
quinthar commentedon Jul 31, 2021
marcaaron commentedon Aug 2, 2021
As far as emulation goes, my understanding is that iOS will be faster because Xcode compiles for x86 and Android Studio emulates ARM.
quinthar commentedon Aug 2, 2021