Decorations are slow
See original GitHub issueWe 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.
- Slate version: 0.33.3 on Chrome
- Example: visit https://gitbookio.github.io/slate-prism/ paste a non-trivial code snippet (~100 lines) and start typing inside it
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:
- with highlighting:
16437ms
to render the app and document - without:
899ms
to render the app and document
I also measured the time spent in the calls of the decorateNode
of the plugin, which amounts to 188ms
. So the issue most likely comes from Slate and the way decorations are applied and rendered.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (8 by maintainers)
Top Results From Across the Web
What Is Slow Decorating? The Sustainable Home Trend ...
Slow decorating encourages finding antiques, buying used but quality items, and updating older pieces for continued use. It involves purchasing ...
Read more >'Slow Decorating Is The Perfect Antidote To Our Fast- ...
Moving house is expensive but slow decorating allows you to build up your interior over time, spreading out the cost of furniture and...
Read more >Here's a Primer on Slow Decorating - Apartment Therapy
Assuming each room is periodically subject to a close edit, gradually they become greater than the sum of their various parts. Call it...
Read more >Slow Decorating: Decorating When You Don't Know How
With slow decorating, there are no matching sets or professionally put together rooms. That means things can get a little bit wacky without...
Read more >Everything You Need to Know About Slow Decorating
Slow decorating is an interior design approach that promotes taking time to decorate a home. If you patiently get to know your space,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
slate-react
side, by having each Node component order its decoration ranges around its children in advance and only pass down the ones that overlap each child:https://github.com/ianstormtaylor/slate/compare/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
slate-prism
demo page with this build):https://jasonphillips.github.io/slate-prism/
But it’s still not as fast as it could be. I’m relying on
node.getKeysAsArray()
for my orderings and then loop through the children, but there are surely faster ways. That being said, this is already much faster than the current practice of naively passing all decorations down the tree whether or not they fall outside the scope of each child node.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
start
andend
on the same text key) and only pass down the decorations needed.I’ll have a look at @zhujinxuan PRs to see if there are more opportunities