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

Perf MMKV: Avoid multiple writes to same key, use different instances zustand / react-query #656

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

nmalzieu
Copy link
Contributor

@nmalzieu nmalzieu commented Sep 3, 2024

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 again mmkv.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

@nmalzieu nmalzieu requested a review from a team as a code owner September 3, 2024 14:50
@nmalzieu nmalzieu merged commit c8f1641 into main Sep 3, 2024
3 checks passed
@nmalzieu nmalzieu deleted the noe/mmkv-memory-leak branch September 3, 2024 15:13
technoplato pushed a commit that referenced this pull request Dec 17, 2024
Perf MMKV: Avoid multiple writes to same key, use different instances zustand / react-query
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.

2 participants