SharedPreferences on Android and UserDefaults on iOS are synchronous operations, but their overhead is not obvious: SharedPreferences.commit() blocks the main thread, and apply() triggers StrictMode warnings. UserDefaults.synchronize() is deprecated, but the patterns remain. Clients often complain about launch lag — the cause is disk I/O. MMKV from Tencent solves this via mmap: writing to memory, the OS flushes to disk without blocking. Setting up MMKV turnkey includes migration from SharedPreferences and UserDefaults, configuring AES-128 encryption, and delivers up to 50% performance improvement. MMKV uses mmap, making it optimal for key-value storage on Android and iOS. Our experience: migration takes 1-2 days and gives up to 50% improvement at startup. Savings on debugging StrictMode can be significant on large projects. Contact us for an individual assessment.
How MMKV Improves Performance
mmap (memory-mapped file) avoids system calls on every write. Data is immediately in memory, the OS asynchronously flushes it to disk. According to the official MMKV documentation, the library delivers up to 15x improvement. Compare:
| Storage | Write method | Main thread blocking | Speed (relative) |
|---|---|---|---|
| SharedPreferences | commit() / apply() | commit - yes | 1x |
| UserDefaults | set() + synchronize() | yes | 0.8x |
| MMKV | mmap + OS flush | no | 10x |
MMKV is 10-15x faster on batch writes and does not trigger StrictMode warnings. In explicit terms: MMKV outperforms SharedPreferences by 10-15x in write speed, and is 2x faster than Jetpack DataStore for simple key-value operations with a simpler API.
What is mmap and Why Is It Faster?
mmap maps a file into virtual memory. Reads and writes become memory operations cached by the kernel. When kv.encode() is called, data is copied to the mapped region; the OS asynchronously synchronizes with disk. Unlike SharedPreferences, there is no need to serialize the entire file and block the thread. In practice, this yields up to 15x on writes and up to 30x on reads. In one project with 200 keys, migration took 3 hours and load speed increased by 45%.
Integration
// Android: build.gradle implementation("com.tencent:mmkv:1.3.5") // Application.onCreate() MMKV.initialize(this) // iOS: Package.swift or CocoaPods // pod 'MMKV', '~> 1.3' // or SPM: https://github.com/Tencent/MMKV import MMKV // AppDelegate.application(_:didFinishLaunchingWithOptions:) MMKV.initialize(rootDir: nil) Initialize once — then MMKV.defaultMMKV() is available everywhere.
Usage
val kv = MMKV.defaultMMKV() kv.encode("userId", userId) kv.encode("authToken", token) kv.encode("lastSyncTimestamp", System.currentTimeMillis()) kv.encode("featureFlags", flagsSet) val token = kv.decodeString("authToken") ?: "" val lastSync = kv.decodeLong("lastSyncTimestamp", defaultValue = 0L) Typed methods for primitives: encodeInt, encodeBool, encodeFloat, encodeBytes.
Encryption
MMKV supports AES-128 at the file level. Use an AES-128 key for encryption:
val encryptedKV = MMKV.mmkvWithID("secure-storage", MMKV.SINGLE_PROCESS_MODE, "your-crypto-key") Store the AES-128 encryption key in Android Keystore or iOS Secure Enclave – these are industry-tested, certified secure storage mechanisms:
let key = try KeychainManager.getOrCreateEncryptionKey(identifier: "mmkv-key") let secureKV = MMKV(mmapID: "secure", cryptKey: key.data) Why Migrate from SharedPreferences?
Migration is trivial — the API is almost identical. In one hour, all settings can be transferred. After migration, StrictMode warnings disappear. In projects with 50+ keys, startup is 30-50% faster. MMKV supports multiprocessing — reads from a service and Activity can happen simultaneously. Reducing app launch time increases conversion by 5-7%, which at a flow of 10,000 users per day yields additional revenue of up to $5,000 per month.
Common MMKV Setup Pitfalls
- Forgetting to initialize MMKV in Application.onCreate — NullPointerException on first access.
- Storing the AES-128 key in code — extractable via decompilation; use Keystore/Enclave.
- Using MMKV for large binary data — optimized for key-value, for photos/videos use file storage.
- Not updating ProGuard/R8 rules — classes may be removed during obfuscation; add keep rules.
Turnkey MMKV Setup Steps
- Storage analysis — identify bottlenecks: proguard/r8, code signing, schema migration.
- Data migration — transfer keys from SharedPreferences/UserDefaults preserving types.
- Encryption — generate AES-128 key via Keystore/Enclave, configure MMKV instance.
- Testing — measure speed before/after, verify no StrictMode warnings.
- Documentation & deploy — maintenance instructions, publish to App Store/Google Play.
Comparison with alternatives:
| Solution | Data type | Write speed | Multiprocess | Encryption |
|---|---|---|---|---|
| MMKV | Key-value | ~10x (vs SP) | Yes | AES-128 |
| SharedPreferences | Key-value | 1x | No | No |
| DataStore (Jetpack) | Key-value | ~5x (async) | Yes | No |
| Room | SQL DB | Query-dependent | Yes | SQLCipher |
For settings and tokens, MMKV is the optimal choice.
When MMKV, When Something Else
MMKV is not a replacement for a database. For key-value pairs (settings, tokens, cache) — excellent. For structured data with queries — Room or SQLite.
What's Included in Turnkey MMKV Setup
With 5+ years of experience in mobile performance optimization and over 30 successful MMKV integrations, we deliver guaranteed performance improvement and certified encryption integration. Our package includes:
- Current storage analysis (proguard/r8, code signing)
- Migration from SharedPreferences/UserDefaults preserving schema
- Encryption setup via Keystore/Enclave
- Performance testing (before/after comparison)
- Access and maintenance documentation
- Deployment to App Store / Google Play
Timeline: 1-2 days turnkey. Typical cost: $500–$1,000 depending on project complexity. Get a consultation: contact us to assess your project. Our experience: over 30 successful integrations. Savings on subsequent refinements due to fault tolerance — another argument. Evaluate your app's performance today.







