Expensify / react-native-onyx

Persistent, offline-first state management solution for React Native. Easy to use with minimal config and boilerplate.
MIT License
160 stars 73 forks source link

perf: improve native apps startup #563

Closed hurali97 closed 4 months ago

hurali97 commented 4 months ago

Details

The changes in the PR are part of improving the app startup which was profiled for the native Apps. The main change is explained below, the other changes are self explanatory.


Prior to the following change, we had 2.4 seconds being consumed in the loop. We can improve this by doing a multiGet and then doing a loop over returned keys. This reduces the execution time to 250 ms, saving us 2 seconds.

Screenshot 2024-06-20 at 6 12 54 PM

Before: Screenshot 2024-06-20 at 6 17 19 PM

After: Screenshot 2024-06-20 at 6 18 03 PM


Related Issues

https://github.com/Expensify/App/issues/43746

Automated Tests

Manual Tests

Author Checklist

Screenshots/Videos

Android: Native https://github.com/Expensify/react-native-onyx/assets/47336142/a0e2ff33-eb62-45ad-8aed-fb2bddcb18ea
Android: mWeb Chrome https://github.com/Expensify/react-native-onyx/assets/47336142/16ab1920-f82f-4b1e-8160-7594bddaa272
iOS: Native https://github.com/Expensify/react-native-onyx/assets/47336142/a215f721-a281-4937-8ba9-931404a353bd
iOS: mWeb Safari https://github.com/Expensify/react-native-onyx/assets/47336142/7f24c6fa-ac8c-482e-842a-1c5f7d778ff9
MacOS: Chrome / Safari https://github.com/Expensify/react-native-onyx/assets/47336142/728ef8b3-86c1-404f-8945-276258902834
MacOS: Desktop https://github.com/Expensify/react-native-onyx/assets/47336142/983b0783-5836-460b-8c26-e5716542f9b9
hurali97 commented 4 months ago

Looks great overall. I think we can re-use some existing code.

I'm also curious if the for in loops are really helping performance / memory use or if that was just a preference. Disabling eslint is probably fine because I don't think we'll have prototype properties getting in the way, but let's only disable the rule if there's a good reason.

Comparing the before and after profiles, we get 400ms of reduction if we use for...in mainly because we are not doing Object.keys first for target and second for source. These numbers are really noticeable on a large data like ~15k reports.

hurali97 commented 4 months ago

@chrispader @hannojg suggested changes are addressed, would be great to if you guys can re-review 👍

neil-marcellini commented 4 months ago

@hannojg do you want to review once more before we merge? @mountiny feel free to go ahead if you want.

github-actions[bot] commented 4 months ago

🚀Published to npm in v2.0.54