question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decorations are slow

See original GitHub issue

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:

  • 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
jasonphillipscommented, Apr 23, 2018

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.

1reaction
Soreinecommented, Apr 25, 2018

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 and end 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found