yjs / y-indexeddb

IndexedDB database adapter for Yjs
https://docs.yjs.dev/ecosystem/database-provider/y-indexeddb
Other
196 stars 30 forks source link

Wrap initial update syncing in a Doc transaction #11

Closed ajhyndman closed 4 years ago

ajhyndman commented 4 years ago

While doing some experimentation today, I ran into this behaviour that I found surprising.

When initially syncing data from an indexeddb provider, each update is applied independently. This means any registered subscribers also receive the events one at a time, and can waste a lot of energy in the boot up process. Instead, by wrapping the initialisation in a transaction, I can subscribe to the 'afterTransaction' event, and react only to the final, updated state.

I think maybe if you wait to register subscribers until the document has synced from indexeddb, then this is not an issue, but this change seems very helpful for me.

dmonad commented 4 years ago

Awesome, thanks!