ueberdosis / hocuspocus

The CRDT Yjs WebSocket backend for conflict-free real-time collaboration in your app.
https://tiptap.dev/docs/hocuspocus/introduction
MIT License
1.21k stars 117 forks source link

Throttle send and receive in HocuspocusProvider #292

Open ViktorQvarfordt opened 2 years ago

ViktorQvarfordt commented 2 years ago

The problem I am facing When many users are collaborating on a YDoc simultaneously, Yjs updates are sent and received very frequently. This causes strain on the clients and the server.

The solution I would like An optional setting on HocuspocusProvider to throttle both sending and receiving Yjs updates. Essentially simulating a throttled network. The provider can internally use Y.mergeUpdates to batch the throttled updates.

Alternatives I have considered We have considered moving the throttling to the application level rather than the provider, but this doesn't work since conflict resolution would need to be handled. We should of course delegate conflict resolution to Yjs which we get by moving the throttling to the level of Yjs updates.

hanspagel commented 2 years ago

Shouldn’t that happen on the backend side though?

ViktorQvarfordt commented 2 years ago

That could work. However, in that case every keystroke from every user still reaches the server, causing unnecessary load.

hanspagel commented 2 years ago

You’re right. After thinking about this, I like the idea and I think it should be added to the provider. 👍