Tencent / MMKV

An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.
Other
17.39k stars 1.91k forks source link

checkcrc anr when the file it too large #1243

Closed baiiu closed 7 months ago

baiiu commented 7 months ago

The language of MMKV

Objective-C, Swift

The version of MMKV

v1.2.2

The platform of MMKV

iOS

The installation of MMKV

Git clone

What's the issue?

When the file is larger than 4M, there is a possibility that checkcrc anr will occur. How do your fix this problem, hope to get your apply.

What's the log of MMKV when that happened?

libz.1.dylib _adler32_z()
libz.1.dylib _crc32_z()
xxx mmkv::MMKV::checkFileCRCValid(MMKV.cpp:411)
xxx mmkv::MMKV::checkDataValid(MMKV_IO.cpp:233)
xxx mmkv::MMKV::loadFromFile(MMKV_IO.cpp:78)
xxx mmkv::MMKV::MMKV(MMKV.cpp:120)
xxx mmkv::MMKV::MMKV(MMKV.cpp:92)
xxx mmkv::MMKV::mmkvWithID(MMKV.cpp:231)[inlined]
xxx -MMKV initWithMMapID:cryptKey:rootPath:mode:
xxx +MMKV mmkvWithID:cryptKey:rootPath:mode:

lingol commented 7 months ago

Don't use libz's soft implementation of crc32. Use a tuned implementation of crc32 (such as hardware accelerated) if possible. MMKV has some hardware accelerated crc32 inside. I'm not sure why your App doesn't use it.

By the way, you should provide info needed by following the issue template. Things like language & platform help.

lingol commented 7 months ago

And 4M is not considered LARGE for MMKV. Generally speaking, MMKV handles files in that size range very well.

baiiu commented 7 months ago

appreciate for your apply and I'm sorry for that, I have edited my issue.

our platform is iOS, there is a commit turn off crc32 optimization for iOS that mmkv have closed crc32 optimization, does it have any problems on iOS?

lingol commented 7 months ago

It's turned off because back then there were repeated reports from GitHub issues that some device crashed on these crc32 instructions. Theoretically, the libz provided by Apple is already tuned with accelerated hardware.

Exactly how big is your file when this ANR happens?