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

[Bug] Problem with redux-persist #286

Open
ramirobg94 opened this issue Sep 9, 2022 · 8 comments
Open

[Bug] Problem with redux-persist #286

ramirobg94 opened this issue Sep 9, 2022 · 8 comments

Comments

@ramirobg94
Copy link

Describe the bug
I'm facing a problem with redux-persist that can cause a memory and storage leak

Every time a new redux-persist version is created a new key:value pair is stored in the file system.

For example, I have a file with 143 versions, so the size should be 143 times smaller:

Captura de Pantalla 2022-09-09 a las 13 04 16

As you can see in the image I took the file from the container

Captura de Pantalla 2022-09-09 a las 13 04 39

A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Download the application folder and check how many "_persist":"{"version":-1,"rehydrated":true}"}" or key values appear

Expected behavior
All the values stored with the same key should be overwritten like map storage.

Platform Information:

  • OS: iOS
  • React Native Version 0.67.3
  • react-native-mmkv: ^2.4.3
    "react-redux": "^8.0.2",
    "redux": "^4.2.0",
    "redux-persist": "^6.0.0",
@ammarahm-ed
Copy link
Owner

Does this affect reading the data? Or no?

@ramirobg94
Copy link
Author

ramirobg94 commented Sep 9, 2022

No, this doesn't affect reading the data.
But the amount of storage used in the filesystem grows and grows...

Maybe the problem is how the set is implement into the MMKV library

@ammarahm-ed
Copy link
Owner

Its how mmkv is designed and why it is fast because it does not measure and increase file size on each entry but grows exponentially. So 128 to 256 to 512 to 1024 to 2048 and so on. If you need something accurate, it will be slower. So you have to choose what you want, speed or size.

@ramirobg94
Copy link
Author

ramirobg94 commented Sep 11, 2022

wait, if you do this

MMKV.set('a', 1)
MMKV.set('a', 1)
MMKV.set('a', 1)
MMKV.set('a', 1)

the results should be

'a':1
'a':1
'a':1
'a':1

instead of:

'a':1

How should be invalidated the cache? and how the versioning works?

@aLemonFox
Copy link

Can we get some more details about this? I am having the same issue, which makes this lib pretty much useless. I am using it with react-navigation state persistence, which stores the current navigation stack in mmkv for every screen change (so the user returns back to it after app restart). Within minutes my storage has grown to 50mb usage.

@GollyJer
Copy link

GollyJer commented Nov 16, 2022

Its how mmkv is designed and why it is fast because it does not measure and increase file size on each entry but grows exponentially. So 128 to 256 to 512 to 1024 to 2048 and so on. If you need something accurate, it will be slower. So you have to choose what you want, speed or size.

In your opinion what's the best option if size is a concern?

@billnbell
Copy link

does someone have a sample repo to see this?

@nazmeln
Copy link

nazmeln commented Sep 28, 2023

Hey, @ramirobg94
Have you solved this issue?

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

No branches or pull requests

6 participants