Poor performance on re-render
See original GitHub issueDescribe the bug
Any time React does a re-render on the SyntaxHighlighter
component, the component does a full re-parse, re-highlight of the entire document even when the document hasn’t changed. The most egregious offender is getCodeTree
and next up is processLines
.
I think the fix here is to simply wrap these in useMemo
.
To Reproduce Steps to reproduce the behavior:
- Render a large file.
- Note that re-renders are still very slow.
Expected behavior A clear and concise description of what you expected to happen.
Screenshots
Video: https://youtu.be/N01PEn3BZIk
Desktop (please complete the following information):
- OS: macOS 10.15.4
- Browser Chrome, FireFox
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Fix the slow render before you fix the re-render - Kent C. Dodds
It doesn't matter if 100% of your renders are necessary, if those renders are slow, it will still produce a bad experience for...
Read more >Should you optimize every re-render? - Kevin Farrugia
Not all re-renders are bad. Not all re-renders are equal. Some re-renders are more CPU intensive than others. You may debug React re-rendering...
Read more >Improving component's re-render performance | Dimitrios Lytras
It has always been. No point thinking about these pesky re-renders. Our components were slow from the start. Extracting expensive computations.
Read more >How many re-renders is too many? - Alex Sidorenko
The number of re-renders is a poor performance metric. The long tree of React components that only return JSX can be re-rendered many...
Read more >Optimizing React performance by preventing unnecessary re ...
Re-rendering React components unnecessarily can slow down your app and make the UI feel unresponsive. This article explains how to update ...
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 Free
Top 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
I’m having this same problem with large files. I still haven’t found a workaround for this issue.
Thanks @simmerer !