Performance on `IndexeddbPersistence`
I'm investigating the benchmark between y-indexeddb and our @toverything/y-indexeddb (not published yet) because of Our application's requirements for the first screen speed.
I run some basic bench(not accurate), but it looks like the boost speed when creating multiple persistence is much slower than the package we maintained
create many persistence
[
PerformanceMeasure {
name: 'yjs',
entryType: 'measure',
startTime: 1138.3797089457512,
duration: 3805.7039580345154,
detail: null
},
PerformanceMeasure {
name: 'toeverything',
entryType: 'measure',
startTime: 4944.275416970253,
duration: 1129.9851250052452,
detail: null
}
]
async function yjs_create_persistence(n = 1e3) {
for (let i = 0; i < n; i++) {
const yDoc = new Y.Doc();
const persistence = new IndexeddbPersistence('test', yDoc);
await persistence.whenSynced;
persistence.destroy();
}
}
async function toeverything_create_provider(n = 1e3) {
for (let i = 0; i < n; i++) {
const yDoc = new Y.Doc();
const provider = createIndexedDBProvider('test', yDoc);
provider.connect();
await provider.whenSynced;
provider.disconnect();
}
}
Source Code
- https://github.com/toeverything/AFFiNE/blob/master/packages/y-indexeddb/benchmark/index.ts
- https://github.com/toeverything/AFFiNE/blob/master/packages/y-indexeddb/src/index.ts
Hi @Himself65,
y-indexeddb performs some (non-blocking!) sanity checks at startup. However, the whenSynced event fires after the sanity checks are performed. I just added a change so that whenSynced is fired as soon as all updates are retrieved. Now the whenSynced event fires in 5ms instead of 40ms.
Note that instantiating the y-indexeddb database never blocks the main-thread. However, it requires database access. Please be careful when creating multiple y-indexeddb instances in series. Usually, we only need one. We can only destroy/create a new y-indexeddb provider once all sanity checks are performed.