Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backup] Experimentation of react-native-mmkv to store local backup config #1097

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zatteo
Copy link
Contributor

@zatteo zatteo commented Dec 29, 2023

This branch is not meant to be merged. It is just an experimentation to understand the advantages, drawbacks and implications of react-native-mmkv.

Backup current implementation uses react-native-async-storage to store local backup config. I decided to store the FULL config (backup status, uploaded media list, media to upload list, ...) in ONE key as a stringified JSON object to avoid any state issue.

But this lead to multiples issues because the local backup config can take tens of MB when there are a lot of medias, so we have :

  • very slow read and write on iOS and Android
  • cursor issues on Android (solved here)
  • cursor issues on Samsung devices (not solved)

There are multiple solutions to these issues. Here I try react-native-mmkv instead of react-native-async-storage which is known to be very fast. It may be a quick win without changing the algorithm too much and benefiting the entire app.

In this branch, I only try react-native-mmkv with backup feature.

Performance result

  react-native-async-storage react-native-mmkv
getData read 1 87.39 ms. 21.07 ms. 😍
getData parse 1 77.93 ms. 113.39 ms. ⁉️
getLocalBackupConfig 1 166.04 ms. 136.83 ms.
getData read 2 86.70 ms. 9.45 ms. 😍
 getData parse 2 91.78 ms. 152.54 ms. ⁉️
getLocalBackupConfig 2 179.14 ms. 163.91 ms.
storeData parse 66.36 ms. 83.10 ms.
storeData write  1609.73 ms. 205.22 ms. 😍

We can see a 5x to 10x performance boost. UX is better. I do not understand the parsing differences and I do not know if they are relevant.

Other results

  • With RN < 0.71, we need to install react-native-mmkv 2.5.1.
  • To migrate completely, we should before use /lib/localStore/storage helpers everywhere before.
  • Migration code supplied by react-native-mmkv seems to work correctly.

Tested

  • very slow read and write on iOS and Android : SOLVED
  • cursor issues on Android : SOLVED
  • cursor issues on Samsung devices : SOLVED

@zatteo zatteo mentioned this pull request Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant