Skip to content
opfs-lsm

Fast local storage for your web app

Example app
Starting the app

Adapters ​

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

Replaces indexedDBCollectionOptions
sh
pnpm add @opfs-lsm/tanstack-db @opfs-lsm/docstore @opfs-lsm/kv
ts
import { 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") }), 
);

What kv gives you ​

Lightweight ​

The wasm engine loads in parallel with the open, outside your main bundle

ts
// 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" });

Quota management ​

A reserve gives space back when the browser refuses a write, and your app picks what to drop

ts
const db = await openDb({ name: "app" });
db.onStorageFull(({ need }) => evict(need));

Live subscriptions ​

Every write, from any tab, in order

ts
db.changes((event) => {
  if (event.kind !== "append") return;
  render(event.seq, event.ops);
});

Snapshot reads ​

Reads that later writes cannot change

ts
await db.view(async (snap) => {
  const issue = await snap.get(issueKey);
  for await (const { key, value } of snap.range(ofIssue)) {
    render(key, value);
  }
});

Under the hood ​

Open
0:00 / 0:54
Two tabs share one database
Above the line, two tabs of an app. Below it, what kv runs and stores in the browser.

How it works · What kv promises · Engine design · How each promise is verified · Browser support

Our benchmarks ​

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.

Against IndexedDB

Opening a screen docstore against Dexie

A task tracker at 200,000 issues, timed to the last answer. Medians of 5 runs on an Apple M5 Max

  • A board, 6 reads at once, in a fresh tab: 8.10 ms on docstore against 15.7 ms on Dexie, 1.9× as fast.
  • The same board, read again: 1.06 ms on docstore against 11.9 ms on Dexie, 11× as fast.
  • An issue with its comments, in a fresh tab: 6.68 ms on docstore against 2.18 ms on Dexie, 0.33× as fast.
  • The same issue, read again: 0.0917 ms on docstore against 0.391 ms on Dexie, 4.3× as fast.

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.

Your library on opfs-lsm against each library's IndexedDB storage

TanStack DB, y-indexeddb and automerge-repo's IndexedDB storage

  • TanStack DB: cold load of 91,000 rows: 299 ms on opfs-lsm against 1.02 s on the IndexedDB option, 3.4× as fast.
  • TanStack DB: bulk insert, 100,000 rows: 105k rows/s on opfs-lsm against 9.80k rows/s on the IndexedDB option, 11× as fast.
  • Yjs: cold load of 500 notes: 71.9 ms on opfs-lsm against 276 ms on the IndexedDB option, 3.8× as fast.
  • Yjs: reopening right after typing: 16.5 ms on opfs-lsm against 8.36 ms on the IndexedDB option, 0.50× as fast.
  • Automerge: cold load of 500 notes: 249 ms on opfs-lsm against 377 ms on the IndexedDB option, 1.5× as fast.
  • Automerge: reopening right after typing: 63.6 ms on opfs-lsm against 59.0 ms on the IndexedDB option, 0.93× as fast.

No frames dropped while typing, on any of the four, and the runs do not separate the time of one keystroke.

Your own adapter on kv kv against IndexedDB

Medians of 5 runs, 100,000 entries

  • Random writes, batches of 1,000: 391k ops/s on kv against 28.0k ops/s on IndexedDB, 14× as fast.
  • Random point reads: 506k ops/s on kv against 16.5k ops/s on IndexedDB, 31× as fast.
  • Single put, awaited one at a time: 7.89k ops/s on kv against 9.24k ops/s on IndexedDB, 0.85× as fast.
  • Opening the database in a fresh tab: 5.55 ms on kv against 0.348 ms on IndexedDB, 0.063× as fast.

Against SQLite on OPFS

Opening a screen docstore against SQLite on OPFS

The same tracker at 20,000 issues, timed to the last answer. Medians of 5 runs on an Apple M5 Max

  • A board, 6 reads at once, in a fresh tab: 7.02 ms on docstore against 8.59 ms on SQLite on OPFS, 1.2× as fast.
  • The same board, read again: 0.775 ms on docstore against 1.61 ms on SQLite on OPFS, 2.1× as fast.
  • An issue with its comments, in a fresh tab: 5.90 ms on docstore against 4.29 ms on SQLite on OPFS, 0.73× as fast.
  • The same issue, read again: 0.0823 ms on docstore against 0.210 ms on SQLite on OPFS, 2.6× as fast.

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×.

Edits and sync docstore against SQLite on OPFS

20,000 issues, 42,000 comments, 120 people. Medians of 5 runs on an Apple M5 Max

  • Opening the store in a fresh tab: 16.9 ms on docstore against 20.3 ms on SQLite on OPFS, 1.2× as fast.
  • One edit: 0.222 ms on docstore against 3.40 ms on SQLite on OPFS, 15× as fast.
  • Sync, mean of 851 batches of about 50 changes: 2.05 ms on docstore against 10.5 ms on SQLite on OPFS, 5.1× as fast.
  • Import, mean of 47 batches of up to 1,000 rows: 10.5 ms on docstore against 17.6 ms on SQLite on OPFS, 1.7× as fast.
  • Re-reading the 50 latest issues during the sync: 0.427 ms on docstore against 0.404 ms on SQLite on OPFS, 0.94× as fast.

SQLite waits for each commit to be crash-safe before returning, its default. docstore returns sooner, with Chrome's relaxed durability.

Sync under open screens TanStack DB live queries, docstore against SQLite

The tracker through TanStack DB, both on demand, with four screens open as live queries while the sync batches land

  • Opening the collections in a fresh tab: 11.1 ms on docstore against 71.7 ms on SQLite, 6.5× as fast.
  • First answer: a project's todo column: 24.8 ms on docstore against 42.8 ms on SQLite, 1.7× as fast.
  • First answer: the 50 latest issues: 9.85 ms on docstore against 10.4 ms on SQLite. The runs do not tell them apart.
  • A sync batch, four screens open: 6.80 ms on docstore against 128 ms on SQLite, 19× as fast.

‡ 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.

Every table · How we measure