BitPhinix / slate-yjs

Yjs binding for Slate
https://docs.slate-yjs.dev
MIT License
514 stars 73 forks source link

CPU hits 100% when typing fast on large document #313

Closed aumkar closed 2 years ago

aumkar commented 2 years ago

In previous week I started evaluating Y.js and its integration with slate.js, because of facing some OOM and performance issues with slate-collaborative.

So first thing I wanted to is to benchmark Y.js for my use case. Libraries I’m using are:

I tried to create some large data by hand, so that the JSON created for slate.js object is around 800KB. I was able to collaborate just fine, but when typing faster than normal CPU hits 100%, which also resulted in some lag in reflecting typed words in editor.

Screenshot from 2022-01-22 22-21-40-1

Profiling dump (Generated from Chrome) Is it expected behaviour OR I’m doing something wrong?

BitPhinix commented 2 years ago

Hard to pin-point what exactly is causing this without having the exact example, but looking at the dump it looks like it's mostly react reconciliating the dom/slate normalizing and not slate-yjs that is causing the massive CPU usage (which aligns with the benchmarks I've done, the thing slowing down large docs is slate(-react) itself and not slate-yjs)

aumkar commented 2 years ago

Thanks a lot @BitPhinix for quick turn around! Confirming that slate-yjs is not causing this issue. I'm able to reproduce it even without using withYjs and withCursor wrappers for the same test data.