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-signalsFor apps that outgrew their store
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.
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();
What’s included
Memory management
Data in an app arrives from several queries, sockets and local edits. With a plain store, you write the code that clears it.
// 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]);
}
const users = oimdb.entities<User>({
slotReleasePolicy: new OIMSlotAfterIdleReleasePolicy({ keepAfterIdleMs: 30_000 }),
});
function useUser(id: string) {
return useOIMSourceTrackingValue(() => users.getEntityByKey(id), [id]);
}
users · u422readersBoth screens show the user.
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.
Benchmarks
Every operation, next to the hand-written code it replaces.
entityService. slotContentService. findEntityByKey( storeSlot, id)map.get(id): 20 nsThe same Map lookup, one call deeper.slot. 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.entityService. 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.slot. 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().bucket. getBucketMemberSlotCount( )set.size: 1 nsThe same Set read. A list here is an index, like tasks grouped by columnId.slot. updateEntity( patch); db. flush( )a Set of changed ids and a Map of handlers per id, called at flush: 63 nsMost 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.
Tags mount and unmount, every deck is renamed, every card toggled and a setting changes, all in one update.
1.8× faster than alien-signalsA record identified by an (owner, item) pair is found and changed; only the view showing it updates.
1.6× faster than mobxAn owner’s name changes; the list showing it next to each item updates, the other list does not.
1.4× faster than mobxA component that reads many entities mounts, sees a change, unmounts and must not see the next one.
1.3× faster than tanstack-storeA card’s text changes. The list that shows it re-renders; a list over another group is not even woken.
On par with alien-signalsarm64 8× Apple M1, Node v24.16.0, 10,000 entities in the store. Full benchmark →
Try it
Edit a task on the board below. Highlighted cards are the only ones that re-rendered.
At scale
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.
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.
Measured in your browser, on this page. The same comparison on 47 tasks and 17 libraries is on the benchmarks page.
Install @oimdb/core, declare a collection, and subscribe to it from any component.
Recommended together with
cnstracnstra 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 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 →