-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Decorations are slow #1788
Comments
I'm also making heavy use of decorations in a project, and seeing similar performance problems that I suspect are rooted here (mainly since disabling all my decorations shows a speed-up). In my case, the decorations are injected externally upon certain events (meaning, somewhat like the search-highlighting demo here) rather than updated on each change via a |
My very preliminary performance profiling suggested that the slowdown may be related to |
Even though getKeysAsArray() is memoized, the repeated scans across that large array via indexOf() could be the issue. |
So this is probably not the final / optimal solution to the problem, but may indicate a direction: I can see that the main slowdown is simply that the react component for each child node (of a decorated code block, etc) currently receives all the decorations in its props (which may be hundreds in this case) and then iterates over all of them. What is needed is for decorations to not simply be passed to all children down the tree without discretion, and instead to be sent only to the children that overlap the decoration ranges. Here I attempted that just on the master...jasonphillips:speed-up-decorations-rendering That leads to a significant speed-up, which you should be able to see here (I merely updated the https://jasonphillips.github.io/slate-prism/ But it's still not as fast as it could be. I'm relying on |
I'll see if I can improve upon your design @jasonphillips. As is, the performance feels good already. I was thinking about converting the list of decorations to a sorted list of trivial decorations (a decoration with I'll have a look at @zhujinxuan PRs to see if there are more opportunities |
Hi, @jacobbloom I made two small fixes in slate-react->text.js for that problem. Can you try that fix in your document and see whether that works? (If perfect, we will not worry about areSorted any one in decs) |
@zhujinxuan did you mean to pull me into this or was that an autocomplete mistake? |
He meant to mention @jasonphillips FYI I have an opened PR on our fork, continuing on the work of @jasonphillips https://github.com/GitbookIO/slate/pull/3 |
@zhujinxuan where can we see your changes? |
Sorry, I made the wrong mention. The change can be seen in #1771 at the slate-react-> text.js where startKey === endKey |
We are investigating huge performance issues since we updated our app to Slate 0.33, and have noticed that using a syntax highlighting plugin, like
slate-prism
, slows everything a lot.I have measured our the time to
React.renderToString
our app on a reasonable page containing code blocks like this one. Here are the times:16437ms
to render the app and document899ms
to render the app and documentI also measured the time spent in the calls of the
decorateNode
of the plugin, which amounts to188ms
. So the issue most likely comes from Slate and the way decorations are applied and rendered.The text was updated successfully, but these errors were encountered: