mrousavy / react-native-mmkv

⚡️ The fastest key/value storage for React Native. ~30x faster than AsyncStorage!
https://mrousavy.com
MIT License
5.91k stars 254 forks source link

Why it can't use mmkv from central maven rather than building from mmkv submodule? #714

Closed wood1986 closed 1 month ago

wood1986 commented 1 month ago

I have a scenario that my app has a direct dependency on mmkv. This means I am using implementation 'com.tencent:mmkv:1.3.9' in the build.gradle on android. I want to use react-native-mmkv for the react-native area mostly. But I cannot exclude a use case that react-native and native will access the same mmkv store. With this situation, my app will have two copy of mmkv.

iOS is using the cocoapod. If I specify MMKV in the podfile, I believe my app and the react-native-mmkv are using the same mmkv and no duplication.

So my question why this lib needs to build the mmkv from submodule?

maintenance-hans[bot] commented 1 month ago

Guten Tag, Hans here! 🍻

Your question is valid, but it seems like you are looking for a specific solution rather than reporting a bug. The reason we use the submodule for MMKV is to ensure compatibility with the React Native library, and ease the integration process. If you prefer to use a centralized version, you could try implementing a custom setup, but keep in mind there may be challenges with compatibility down the line.

If you want this to be addressed in a tailored manner, I suggest providing more details and perhaps opening a discussion in our discussions tab. Also, if you wish for quicker responses or dedicated support, consider supporting the project via sponsorship.

Let us try to have a constructive conversation about potential solutions.

Note: If you think I made a mistake, please ping @mrousavy to take a look.

mrousavy commented 1 month ago

Hey!

This is because react-native-mmkv actually uses MMKV's C++ library, through direct JSI bindings. If you browse the codebase, you can see there is no Java code for accessing MMKV.

This way, it's faster, and more portable - and we can also fully re-use the code from the iOS codebase.

iOS is using the cocoapod. If I specify MMKV in the podfile, I believe my app and the react-native-mmkv are using the same mmkv and no duplication

Not true, nope. iOS also uses the C++ submodule codebase.

wood1986 commented 1 month ago

Hey @mrousavy

This is because react-native-mmkv actually uses MMKV's C++ library, through direct JSI bindings. If you browse the codebase, you can see there is no Java code for accessing MMKV. This way, it's faster, and more portable - and we can also fully re-use the code from the iOS codebase.

I know this but you are not answering my question. In my case, the app is not a pure react-native app and other team integrate react-native into this app. It already has MMKV dependency in gradle file 'com.tencent:mmkv:1.3.9'. That team want to use mmkv via this library(react-native-mmkv). Now the app has two copy of MMKV. One is from central maven. The other is from this library. Does it sound right to you?

Not true, nope. iOS also uses the C++ submodule codebase.

If iOS use c++ submodule, why the react-native-mmkv.podspec has this line. I expect it should build from the source from the c++ submodule and it should not need to depend on MMKV

image

mrousavy commented 1 month ago

If iOS use c++ submodule, why the react-native-mmkv.podspec has this line.

You are using the "old" react-native-mmkv (V2). The new one (V3) has been using MMKV from source since a few months now.

Now the app has two copy of MMKV. One is from central maven. The other is from this library. Does it sound right to you?

No, it does not sound right to me.

I know this but you are not answering my question.

Do you mean the original question "So my question why this lib needs to build the mmkv from submodule?"?

Then I already gave you an answer to that.

image


With that said, you're probably asking me now how to combine react-native-mmkv and the Gradle/Podspec MMKV dependencies.

My answer is; I don't know. That's tricky.

If you inspect the Gradle dependency, you'll see that the C++ code is not in there as a prefab, so I cannot use it. I need to build it from source. That is also much more lightweight for everyone else, since we don't need Java/JNI bindings or ObjC bindings - just pure C++, as fast as it can be.

wood1986 commented 1 month ago

Just FYI: image

mrousavy commented 1 month ago

yup, would be cool to build C++ MMKV as a shared lib (so)