Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance on IndexeddbPersistence #29

Open
himself65 opened this issue Apr 11, 2023 · 1 comment
Open

Performance on IndexeddbPersistence #29

himself65 opened this issue Apr 11, 2023 · 1 comment
Labels

Comments

@himself65
Copy link

himself65 commented Apr 11, 2023

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

@dmonad
Copy link
Member

dmonad commented May 4, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants