Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsMay 19, 2026·3 min de lectura

MMKV — Efficient Mobile Key-Value Storage Framework by WeChat

MMKV is a high-performance key-value storage framework developed by WeChat. It uses memory-mapped files and protobuf encoding to deliver fast, reliable persistence on Android, iOS, macOS, Windows, and POSIX systems.

Listo para agents

Este activo puede ser leído e instalado directamente por agents

TokRepo expone un comando CLI universal, contrato de instalación, metadata JSON, plan según adaptador y contenido raw para que los agents evalúen compatibilidad, riesgo y próximos pasos.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
MMKV Overview
Comando CLI universal
npx tokrepo install 4f654acd-5318-11f1-9bc6-00163e2b0d79

Introduction

MMKV is an efficient, small, and easy-to-use mobile key-value storage framework created by the WeChat team at Tencent. It relies on memory-mapped files (mmap) for persistence and Protocol Buffers for serialization, achieving read and write speeds that far exceed SharedPreferences and NSUserDefaults.

What MMKV Does

  • Provides persistent key-value storage using memory-mapped files for near-instant writes
  • Supports multiple data types including strings, integers, floats, byte arrays, and custom Parcelable/NSCoding objects
  • Offers multi-process concurrent read/write on Android via file locking
  • Delivers cross-platform support for Android, iOS, macOS, Windows, POSIX, and HarmonyOS
  • Enables data encryption with AES-128/CFB for sensitive values

Architecture Overview

MMKV maps a file into virtual memory using mmap, so writes go directly to the kernel page cache without explicit I/O calls. Data is encoded with Protocol Buffers in an append-only log. When the file grows beyond a threshold, MMKV performs a full rewrite to reclaim space. A CRC checksum guards against corruption from unexpected process termination.

Self-Hosting & Configuration

  • Add the dependency for your platform (CocoaPods, Gradle, pip, or CMake)
  • Initialize MMKV once at app startup with a root directory path
  • Optionally set a per-instance encryption key for AES-128 protection
  • Enable multi-process mode on Android by passing MMKV.MULTI_PROCESS_MODE
  • Tune the page-size or file-growth strategy for workloads with very large values

Key Features

  • Blazing speed: benchmarks show 1000x faster than SharedPreferences on Android
  • Tiny binary size of roughly 400 KB on mobile platforms
  • Thread-safe and multi-process-safe with granular file locks
  • Automatic data migration helpers from SharedPreferences and NSUserDefaults
  • Mature and battle-tested in WeChat, serving over a billion monthly active users

Comparison with Similar Tools

  • SharedPreferences — Android-only, synchronous XML I/O, much slower for frequent writes
  • NSUserDefaults — Apple-only, plist-backed, no encryption or multi-process safety
  • DataStore (Jetpack) — Google's modern replacement for SharedPreferences, but Android-only and coroutine-based
  • Realm — Full object database with queries, heavier footprint than a simple KV store
  • LMDB — Also mmap-based, but targets server workloads and lacks mobile-first APIs

FAQ

Q: Does MMKV handle process crashes safely? A: Yes. Because mmap writes go to the OS page cache, data survives app crashes. A CRC check detects partial writes on next load.

Q: Can I use MMKV as a general-purpose database? A: MMKV is designed for flat key-value data. For relational or document data, use a proper database like SQLite.

Q: How large can an MMKV file grow? A: There is no hard limit, but MMKV is optimized for many small values. Files over tens of MB may trigger more frequent full-rewrites.

Q: Is MMKV open source? A: Yes. MMKV is released under the BSD 3-Clause license on GitHub.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados