Writing
How to Make Local Storage Fast in React Native with MMKV
Make React Native local storage fast: why AsyncStorage feels slow, how much faster MMKV is, migration code, Zustand and TanStack Query setups and SQLite tips.
Arbab Naseer Published Last updated 8 min read
- React Native
- MMKV
- Performance
- Expo
- TypeScript
- SQLite
Short answer: the fastest local storage for React Native is MMKV. It reads about 20 times faster than AsyncStorage in the published benchmark because it is synchronous C++ with no Promise round trip. To make your app fast, move small and frequently used data to MMKV, read it synchronously at startup, keep values small, write less often, and use SQLite with indexes and transactions for anything that looks like a table.
On a React Native social app with feeds, profiles and messages, local data goes through MMKV, and that is a big part of why screens open with content already there on mid range Android phones. If you are still choosing which storage to use at all, start with my comparison of MMKV, AsyncStorage, SQLite and SecureStore. This article is about speed.
Why local storage makes an app feel slow
Storage rarely shows up as one big slow call. It shows up as a lot of small delays:
- Async reads at startup. Every
await AsyncStorage.getItem()before the first screen is a frame or more where the user sees a spinner or a flash of the default theme. - One giant JSON value. Saving the whole app state under one key means every small change rewrites and re-parses the entire blob.
- Writing on every keystroke. A draft saved on each character turns typing into a stream of disk writes.
- Filtering in JavaScript. Loading 5000 records from a key value store to show 20 of them wastes memory and time that a database query would not.
The fix for the first three is a faster key value store used carefully. The fix for the last one is a real database.
Which local storage is the fastest?
The StorageBenchmark app reads one value 1000 times from each library. AsyncStorage needed 242 ms for that. Here is how many reads every other library finishes in the same 242 ms:
The same numbers as a table:
| Library | 1000 reads | Per read | Compared to MMKV |
|---|---|---|---|
| MMKV | 12 ms | 0.012 ms | fastest |
| WatermelonDB | 53 ms | 0.053 ms | 4.4x slower |
| Realm | 81 ms | 0.081 ms | 6.8x slower |
| SQLite (react-native-quick-sqlite) | 82 ms | 0.082 ms | 6.8x slower |
| AsyncStorage | 242 ms | 0.242 ms | 20x slower |
A single read is fast with any of them. The difference matters because apps do hundreds of reads: every persisted store, every cached query, every hook that checks a setting. Two things to keep honest: the benchmark ran in a debug build on React Native 0.68, and AsyncStorage has since moved to a new SQLite backend in version 3. I explain how to run the same test on your own device further down.
Why MMKV is so much faster
Three things add up:
- No Promise and no bridge. react-native-mmkv calls C++ directly through JSI. A read returns the value on the same line, so there is no
await, no queue and no extra render while you wait. - Memory mapped file. MMKV maps its file into memory with
mmap. Reading a key is a memory lookup, and writes go to memory first while the operating system saves them to disk. - Compact encoding. Values are stored with protobuf, which is small and quick to encode and decode.
Step 1: move hot data to MMKV
Install it (versions on npm when I wrote this: react-native-mmkv 4.3.2 with react-native-nitro-modules 0.37.1):
# Expo (needs a development build, not Expo Go)
npx expo install react-native-mmkv react-native-nitro-modules
npx expo prebuild
# Bare React Native
npm install react-native-mmkv react-native-nitro-modules
cd ios && pod install
MMKV 4 needs React Native 0.76 or newer. If you are in Expo Go today, read Expo Go vs development builds first; it takes about ten minutes to switch.
Create your instances once, in one file, and import them everywhere:
// storage.ts
import { createMMKV } from 'react-native-mmkv';
// App wide values: theme, language, onboarding, feature flags
export const appStorage = createMMKV({ id: 'app' });
// Cached server data, safe to wipe at any time
export const cacheStorage = createMMKV({ id: 'cache' });
// Per user values, cleared on logout
export const userStorage = (userId: string) => createMMKV({ id: `user-${userId}` });
Separate instances keep files small and make logout simple: clear the user instance and the cache, keep the app settings.
Step 2: migrate from AsyncStorage without losing data
If your app is already live, users have data in AsyncStorage. Copy it once, then delete it. This is adapted from the official migration guide:
import AsyncStorage from '@react-native-async-storage/async-storage';
import { appStorage } from './storage';
export async function migrateFromAsyncStorage() {
if (appStorage.getBoolean('migratedFromAsyncStorage')) return;
const keys = await AsyncStorage.getAllKeys();
for (const key of keys) {
const value = await AsyncStorage.getItem(key);
if (value == null) continue;
if (value === 'true' || value === 'false') {
appStorage.set(key, value === 'true');
} else {
appStorage.set(key, value);
}
}
await AsyncStorage.multiRemove(keys);
appStorage.set('migratedFromAsyncStorage', true);
}
I import the default AsyncStorage here on purpose: in version 3 it still points to the old v2 data, which is exactly where existing users have their values. Run the migration before your app reads any of those keys, and show your splash screen until it finishes. It only runs once per install.
Step 3: read state synchronously at startup
This is where users actually feel the change. With AsyncStorage, a persisted store loads after the first render, so the app flashes default values and then jumps. With MMKV, the store is ready before the first render.
With Zustand’s persist middleware, give it an MMKV backed storage (Zustand 5.0.16 at the time of writing):
import { create } from 'zustand';
import { persist, createJSONStorage, type StateStorage } from 'zustand/middleware';
import { appStorage } from './storage';
const mmkvStorage: StateStorage = {
getItem: (name) => appStorage.getString(name) ?? null,
setItem: (name, value) => appStorage.set(name, value),
removeItem: (name) => appStorage.remove(name),
};
type Settings = { theme: 'light' | 'dark'; autoplay: boolean; setTheme: (t: 'light' | 'dark') => void };
export const useSettings = create<Settings>()(
persist(
(set) => ({
theme: 'dark',
autoplay: true,
setTheme: (theme) => set({ theme }),
}),
{ name: 'settings', storage: createJSONStorage(() => mmkvStorage) }
)
);
Because the storage is synchronous, the store hydrates when it is created, so the first frame already has the user’s theme. The same pattern works with Redux Persist and Jotai; the MMKV repo has ready made wrappers.
For server data, persist the TanStack Query cache in MMKV so lists show instantly on the next launch while fresh data loads in the background:
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister';
import { cacheStorage } from './storage';
export const queryPersister = createAsyncStoragePersister({
storage: {
getItem: (key) => cacheStorage.getString(key) ?? null,
setItem: (key, value) => cacheStorage.set(key, value),
removeItem: (key) => cacheStorage.remove(key),
},
});
Then wrap your app in PersistQueryClientProvider with persistOptions={{ persister: queryPersister }}. This is the combination I rely on for feed style screens: cached data on screen at launch, fresh data a moment later.
Step 4: keep values small and split by key
MMKV keeps the whole file in memory, and every write stores that key’s full value again, even if only one field inside it changed. So:
- Split large objects. Store
settings.themeandsettings.languageas separate keys instead of onesettingsobject, when they change independently. - Do not store lists of records. A list of 3000 orders as one JSON string is slow to parse and wasteful in memory. That is SQLite’s job.
- Store files as files. Images, PDFs and audio go to the file system. Save only the path in MMKV.
- Trim caches.
cacheStorage.byteSizetells you how big an instance is. CallcacheStorage.trim()after clearing many keys to give memory back.
Step 5: write less often
Fast writes are still writes. Two habits help:
Debounce drafts and text input. Save after the user stops typing instead of on every character:
import { useEffect } from 'react';
import { appStorage } from './storage';
export function usePersistDraft(key: string, text: string) {
useEffect(() => {
const timer = setTimeout(() => appStorage.set(key, text), 400);
return () => clearTimeout(timer);
}, [key, text]);
}
Skip writes that change nothing. If some code sets the same value over and over, create the instance with compareBeforeSet: true. MMKV then compares the new value with the stored one and skips the disk write when they match.
Step 6: make SQLite fast when you need a database
When data really belongs in tables, MMKV is the wrong tool and SQLite is the fast one, as long as you use it well. These are the settings and habits that make the biggest difference, shown with expo-sqlite:
import * as SQLite from 'expo-sqlite';
const db = await SQLite.openDatabaseAsync('app.db');
// WAL lets reads and writes happen at the same time
await db.execAsync('PRAGMA journal_mode = WAL;');
// Index the columns you filter and sort by
await db.execAsync('CREATE INDEX IF NOT EXISTS idx_orders_created ON orders (created_at);');
// Insert many rows in one transaction, not one transaction per row
await db.withTransactionAsync(async () => {
for (const order of orders) {
await db.runAsync('INSERT INTO orders (id, total, created_at) VALUES (?, ?, ?)', order.id, order.total, order.createdAt);
}
});
// Ask only for the columns and rows the screen shows
const page = await db.getAllAsync('SELECT id, total FROM orders ORDER BY created_at DESC LIMIT 20 OFFSET ?', offset);
A transaction around a batch insert is often the single biggest win: without it, SQLite commits and syncs to disk after every row. If you need raw speed beyond this, op-sqlite is a JSI binding built for performance.
If you have to stay on AsyncStorage
Sometimes you cannot add native code yet, for example in an Expo Go prototype. You can still make AsyncStorage feel faster:
- Batch. Use
getManyandsetMany(v3) ormultiGetandmultiSet(v2) instead of loops of single calls. - Read once, keep it in memory. Load settings at startup into a store and read from the store afterwards.
- Do not block the first screen. Show the UI with sensible defaults and apply stored values when they arrive, or keep the splash screen up until the few values you really need are loaded.
Measure it on your own device
Benchmarks from someone else’s phone are a starting point. This snippet compares 1000 reads on your device:
import { createAsyncStorage } from '@react-native-async-storage/async-storage';
import { createMMKV } from 'react-native-mmkv';
export async function storageBenchmark() {
const mmkv = createMMKV({ id: 'bench' });
const asyncStorage = createAsyncStorage('bench');
mmkv.set('key', 'hello');
await asyncStorage.setItem('key', 'hello');
let start = performance.now();
for (let i = 0; i < 1000; i++) mmkv.getString('key');
const mmkvMs = performance.now() - start;
start = performance.now();
for (let i = 0; i < 1000; i++) await asyncStorage.getItem('key');
const asyncMs = performance.now() - start;
console.log(`MMKV: ${mmkvMs.toFixed(1)} ms, AsyncStorage: ${asyncMs.toFixed(1)} ms, ${(asyncMs / mmkvMs).toFixed(1)}x`);
}
Run it in a release build on the cheapest Android phone you can find. Debug builds and simulators give very different numbers, and a slow phone is where your users notice storage first.
FAQ
What is the fastest local storage for React Native?
MMKV, through the react-native-mmkv library. It is synchronous, written in C++ and reads about 20 times faster than AsyncStorage and 4 times faster than the next fastest option in the published StorageBenchmark. For relational data, a JSI SQLite binding such as op-sqlite is the fastest database option.
Why is AsyncStorage slow?
Every call returns a Promise and goes through a native module, so each read waits for the next turn of the JavaScript event loop. With many small reads, especially at startup, those waits add up. It also only stores strings, so objects are parsed from JSON on every read.
Is MMKV 30 times faster than AsyncStorage?
The MMKV README says “~30x”. The published StorageBenchmark numbers (12 ms against 242 ms for 1000 reads) work out to about 20 times. The real gap in your app depends on the device, build type and AsyncStorage version, so measure it with the snippet above.
Does MMKV make the whole app faster?
It makes storage reads and writes faster and removes loading flashes at startup. It will not fix slow lists, heavy renders or large images. If storage is not where your app spends its time, switching gives a smaller gain, so profile first.
Can MMKV replace SQLite?
Only for key value data. If you need queries, sorting, relations or thousands of records, keep SQLite and use MMKV next to it for settings and small cached values.
Is MMKV safe for tokens?
Plain MMKV stores data unencrypted inside the app sandbox, so it is not the right place for tokens. You can turn on AES encryption, but keep the encryption key itself in SecureStore or Keychain. I explain the full setup in how to store auth tokens securely in React Native.
Not sure which storage your app needs in the first place? Read MMKV vs AsyncStorage vs SQLite vs SecureStore. If your React Native app feels slow and you want someone to find out why, get in touch.