Perf MMKV: Avoid multiple writes to same key, use different instances zustand / react-query #656
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was happy because I was having the "freeze on load" issue on my dev app
However I applied a stashed diff that was adding logs and disabling the mmkv cache for react-query and it went through without freezing anymore
So I deep dived on what could cause MMKV to freeze the app and found out this thread about memory leaks:
mrousavy/react-native-mmkv#440
Basically, when you
mmkv.set("a", "test")
then againmmkv.set("a", "test-2")
, by default, MMKV does not replace the first entry (this is by design, to be faster)This makes the file grow kind of uncontrollably (by checking the thread and some chinese comments on the MMKV repo it seems at some point it should still pack the file but maybe it's getting too big too fast)
Another indicator that this might be the issue is that when I returned an empty view from ConversationList it wasn't freezing anymore, showing that this could be linked to the heavy use of react query inside this component
However I'm not 100% sure, just trying the solution from the thread to see if it fixes our freeze issue
I also decided to give react-query a dedicated mmkv instance