ammarahm-ed / react-native-mmkv-storage

An ultra fast (0.0002s read/write), small & encrypted mobile key-value storage framework for React Native written in C++ using JSI
https://rnmmkv.now.sh
MIT License
1.59k stars 111 forks source link

[Bug] Problem with redux-persist #286

Open ramirobg94 opened 2 years ago

ramirobg94 commented 2 years ago

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:

ammarahm-ed commented 2 years ago

Does this affect reading the data? Or no?

ramirobg94 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

does someone have a sample repo to see this?

nazmeln commented 1 year ago

Hey, @ramirobg94 Have you solved this issue?