Keep your library's API. Its adapter stores the data in opfs-lsm instead of IndexedDB.
Live queries over collections, with the whole dataset in the browser.
3.4×faster cold load of 91,000 rows than indexedDBCollectionOptions
pnpm add @opfs-lsm/tanstack-db @opfs-lsm/docstore @opfs-lsm/kvimport { docstoreCollectionOptions } from "@opfs-lsm/tanstack-db";
const kv = await openDb({ name: "app" });
const store = await openDocStore(kv, schema);
const todos = createCollection(
indexedDBCollectionOptions({ db, name: "todos", getKey }),
docstoreCollectionOptions({ collection: store.collection("todos") }),
);The wasm engine loads in parallel with the open, outside your main bundle
// 19.7 kB gzip in your main bundle
import { openDb } from "@opfs-lsm/kv";
// the SharedWorker loads here, but you
// can already do everything without it
const db = await openDb({ name: "app" });A reserve gives space back when the browser refuses a write, and your app picks what to drop
const db = await openDb({ name: "app" });
db.onStorageFull(({ need }) => evict(need));Every write, from any tab, in order
db.changes((event) => {
if (event.kind !== "append") return;
render(event.seq, event.ops);
});Reads that later writes cannot change
await db.view(async (snap) => {
const issue = await snap.get(issueKey);
for await (const { key, value } of snap.range(ofIssue)) {
render(key, value);
}
});How it works · What kv promises · Engine design · How each promise is verified · Browser support
What a user of your app waits for: a screen's reads to the last answer, a first load, an edit, a sync batch landing under open screens.
A task tracker at 200,000 issues, timed to the last answer. Medians of 5 runs on an Apple M5 Max
The board asks for 6 reads as it opens, all started together. Read one at a time, the 11 screens of the full table are all faster on docstore in a warm tab. In a fresh tab 4 are faster and 5 are slower, the issue most of all.
TanStack DB, y-indexeddb and automerge-repo's IndexedDB storage
No frames dropped while typing, on any of the four, and the runs do not separate the time of one keystroke.
Medians of 5 runs, 100,000 entries
The same tracker at 20,000 issues, timed to the last answer. Medians of 5 runs on an Apple M5 Max
Read one at a time, docstore is faster than SQLite on 7 of the 11 screens in a warm tab and slower on 3. In a fresh tab it is faster on 4 and slower on 5, down to 0.52×.
20,000 issues, 42,000 comments, 120 people. Medians of 5 runs on an Apple M5 Max
SQLite waits for each commit to be crash-safe before returning, its default. docstore returns sooner, with Chrome's relaxed durability.
The tracker through TanStack DB, both on demand, with four screens open as live queries while the sync batches land
‡ The runs do not separate the two stores, so the result counts as even.
Frames dropped over 426 batches with the screens open: 31 on docstore, 288 on SQLite. SQLite waits for each commit to be crash-safe, its default; docstore doesn't.
Runs in headless Chrome 157 on an Apple M2 Pro, and on an Apple M5 Max for the task tracker.