Skip to main content
OIMDB

For apps that outgrew their store

Powerful state.
Native speed.

Collections, live indexes, always-sorted lists, computed values and automatic cleanup in the box, at close to the cost of hand-written code on plain Maps and arrays. Subscriptions down to a single field.

tasks.ts
import { OIMDB, createOIMEntitySlotCollectionStoreAggregate, createOIMSlotCollectionIndexStoreAggregate } from '@oimdb/core';

type Task = { id: string; column: string; title: string; priority: number };

const createTaskSchema = (db: OIMDB) => {
const tasks = createOIMEntitySlotCollectionStoreAggregate<Task>(db);
const byColumn = createOIMSlotCollectionIndexStoreAggregate(tasks, { selectKey: (task) => task.column });
return { tasks, byColumn };
};
const db = new OIMDB({ createSchemas: (db) => ({ default: createTaskSchema(db) }) });
const { tasks, byColumn } = db.schemas.default;

db.createEffect(() => {
render(byColumn.getEntitiesByKey('todo').map((task) => task.title));
});

const login = tasks.writeSlotContentByKey('t1', { id: 't1', column: 'todo', title: 'Fix login redirect', priority: 2 });
tasks.writeSlotContentByKey('t2', { id: 't2', column: 'todo', title: 'Ship the release', priority: 1 });
login.updateEntity({ column: 'done' });
db.flush();

Memory management

No manual state cleanup.

Data in an app arrives from several queries, sockets and local edits. With a plain store, you write the code that clears it.

Redux, zustandNothing is dropped until you write a reset, and the reset clears shared state for every screen at once.
Jotai atomFamilyThe family keeps every atom it has created until you call remove or setShouldRemove, and its docs warn about the memory leak.
TanStack Query, RTK QueryA query nobody reads is freed, but an entity fetched by five queries is stored five times.
Relay, ApolloRelay frees data no query retains, for GraphQL data only; with Apollo you call cache.evict() and cache.gc() yourself.
OIMDBEach entity is stored once, whatever source it came from. Lists, sorted views and computed values go when nothing reads them; entities go by the policy you set per collection: when unused, after a grace period, after idle time, or a time to live.
Without OIMDB
// users arrive from the chat socket, the members query and search,
// into one global slice that outlives every component
const readers = new Map<string, number>();
const dropTimers = new Map<string, ReturnType<typeof setTimeout>>();

function useUser(id: string) {
useEffect(() => {
clearTimeout(dropTimers.get(id));
readers.set(id, (readers.get(id) ?? 0) + 1);
return () => {
const left = readers.get(id)! - 1;
readers.set(id, left);
if (left > 0) return;
dropTimers.set(id, setTimeout(() => {
readers.delete(id);
store.dispatch(usersSlice.actions.removeOne(id));
}, 30_000));
};
}, [id]);
return useSelector((state) => state.users.entities[id]);
}
With OIMDB
const users = oimdb.entities<User>({
slotReleasePolicy: new OIMSlotAfterIdleReleasePolicy({ keepAfterIdleMs: 30_000 }),
});

function useUser(id: string) {
return useOIMSourceTrackingValue(() => users.getEntityByKey(id), [id]);
}
users · u422readers

Both screens show the user.

Entities go by the policy you set.

Pick, per collection, when an entity nobody reads is dropped. A timed policy costs nothing until you turn it on, and holdSlotByKey(key) keeps a key alive while a request is in flight.

Lifecycle docs →
  • As soon as nothing reads it
  • A grace period after the last reader leaves
  • After N ms idle
  • A time to live after the last write
  • Whichever comes first
  • Keep while it holds data (default)

Benchmarks

Close to the cost of a plain Map.

Every operation, next to the hand-written code it replaces.

22 nsto readentityService.slotContentService.findEntityByKey(storeSlot, id)map.get(id): 20 nsThe same Map lookup, one call deeper.
7 nsto updateslot.updateEntityColumn('title', value)if (entity.title !== value) { entity.title = value; if (frameOf[i] !== frame) { frameOf[i] = frame; changed.push(i) } }: 5 nsBoth compare the column with its old value, write it and add the entity to the frame’s list of changed entities once, guarded by a per-entity frame stamp. The extra time is what lets db.flush() reach every list and component watching that entity.
81 nsto insertentityService.writeSlotContentByKey(storeSlot, entity.id, entity)if (!map.get(id)) map.set(id, entity): 58 nsThe extra time registers the entity so a component can subscribe to it, and announces the insert at db.flush() to every list and component watching the collection.
to delete54 nsslot.clearSlotContent()map.delete(id): 35 nsWith a plain Map nothing tells the component, so it keeps showing the deleted object. Here it gets undefined at the next db.flush().
to count a list1 nsbucket.getBucketMemberSlotCount()set.size: 1 nsThe same Set read. A list here is an index, like tasks grouped by columnId.
to update by id and notify the watching component54 nsslot.updateEntity(patch); db.flush()a Set of changed ids and a Map of handlers per id, called at flush: 63 ns

Tasks from a real board app, timed end to end.

Most libraries here ship no collections, groups or sorted lists. In those rows the collections are written by hand on top of the library's primitives, without OIMDB, so a row measures that code, not a feature the library ships.

A busy screen

Tags mount and unmount, every deck is renamed, every card toggled and a setting changes, all in one update.

1.8× faster than alien-signals
OIMDB351.62 µs
alien-signals + hand-written collections647.86 µs

Write by a two-part key

A record identified by an (owner, item) pair is found and changed; only the view showing it updates.

1.6× faster than mobx
OIMDB9.11 µs
mobx + hand-written collections14.21 µs

Rename a related entity

An owner’s name changes; the list showing it next to each item updates, the other list does not.

1.4× faster than mobx
OIMDB7.95 µs
mobx + hand-written collections11.51 µs

One component over many entities

A component that reads many entities mounts, sees a change, unmounts and must not see the next one.

1.3× faster than tanstack-store
OIMDB13.82 µs
tanstack-store + hand-written collections17.52 µs

Edit a field on a live list

A card’s text changes. The list that shows it re-renders; a list over another group is not even woken.

On par with alien-signals
OIMDB152.75 µs
A Map with an array per group, no library366.16 µs
alien-signals + hand-written collections154.22 µs

arm64 8× Apple M1, Node v24.16.0, 10,000 entities in the store. Full benchmark →

Try it

Edit one field and only the cards that read it re-render.

Edit a task on the board below. Highlighted cards are the only ones that re-rendered.

At scale

A hundred thousand entities, and a write still costs what one entity costs.

Start the ticker, then switch between OIMDB and zustand. A zustand update copies the whole record of entities; an OIMDB write touches only the entity it changes.

Live

100,000 items, prices ticking every frame

The same virtualised table, the same random writes, two stores. zustand is written the way its docs write a normalised collection: one store, a record by id, an immutable update and one selector per item. zustand has no batching of its own, so every frame's writes go into one setState, its best case. Switch the library, start ticking, and scroll.

NamePriceQtyTotal
0.000ms per frame's writes
0frames per second
0.0item renders per frame
0.0ms to load all items

Measured in your browser, on this page. The same comparison on 47 tasks and 17 libraries is on the benchmarks page.

Next-level state management.

Install @oimdb/core, declare a collection, and subscribe to it from any component.

Recommended together with

cnstra

cnstra decides what happens and in what order. OIMDB holds the data and reacts to it. One line connects them, and every turn of the orchestrator lands in one frame:

cns.addDrainListener(() => db.flush());Using OIMDB with cnstra →
Exodra

Exodra renders the slots. Views only read them, each binding is a tracked effect, and a bucket's children keep their nodes when entities leave it.

npm install @oimdb/exodraThe Exodra plugin →