react-native-mmkv icon indicating copy to clipboard operation
react-native-mmkv copied to clipboard

Android Multiprocess Support?

Open TheSteveHan opened this issue 3 years ago • 4 comments

Hi there,

I've encounter some segfaults today from accessing the storage via both the app and the widget on android.

After a little bit of digging it seems like the mmkv instance for android is hard coded to use single process mode here:

https://github.com/mrousavy/react-native-mmkv/blob/master/android/src/main/cpp/MmkvHostObject.cpp#L19

Is this intentional? For my use case, after changing this flag to MMKV_MULTI_PROCESS the app no longer crashes, although I haven't read enough of the code base to understand the full implication of this change.

TheSteveHan avatar Aug 23 '22 21:08 TheSteveHan

I think multi-process mode is slower because it has to perform more disk-memory synchronisation (it always assumes that data might've changed in the meantime), which single-process mode doesn't have to do.

mrousavy avatar Aug 24 '22 09:08 mrousavy

That makes sense. With this PR https://github.com/mrousavy/react-native-mmkv/pull/402, multiprocess is turned on on ios when AppGroup is specified. Should we add a explicit config option for a uniform way to control this behavior on both ios and android?

TheSteveHan avatar Aug 25 '22 14:08 TheSteveHan

Hey! Yeah I think this should be configurable from both iOS and Android, but not sure how since this is called once the JS bundle loads....

mrousavy avatar Jul 17 '23 11:07 mrousavy

I added android support in https://github.com/mrousavy/react-native-mmkv/pull/611.

On iOS, AppGroups enable this mode. Looking at the MMKV doc, MultiProcess mode on iOS only makes sense with AppGroups and needs to be initialized when the bundle js loads

On Android, this is not the case, MultiProcess mode is enabled when creating the instance so we can just add it as a config parameter.

maxencehenneron avatar Nov 23 '23 03:11 maxencehenneron