Reduce number of component updates
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What’s the current behavior?
Render time is slow.
In the HugeDocument example, a keypress event takes ~300ms (CPU slowed down 6x)
Compare that to the exact same document, but without updates propagated through react. It’s <100ms:
Proposal:
(Re)introduce selective rendering logic.
As I understand it, here’s the current flow:
- key event
- add OT to the queue
- flush the OT queue
- update the component via setState
- react updates DOM (EXPENSIVE)
- reset scroll & selection range via cDU (EXPENSIVE)
Here’s an improved flow:
- key event
- add OT to the queue. Each OT that has a behavior that is different than the native DOM content editable behavior sets a 1-way
pushUpdate
flag - flush the OT queue
- update the component via setState
- use
shouldComponentUpdate = () => value.get(pushUpdate)
- If update, do steps 5 & 6 above
Key notes:
- An enhanced solution is to delay flushing the OT queue until it’s required (eg a request to serialize), similar to what immutable-js does. I’m ruling this out of scope to keep it simple.
- This is a blocker for Android support #1935.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:15 (9 by maintainers)
Top Results From Across the Web
How to Reduce the Number of Re-renders When Updating ...
We can reduce the number of re-renders to components with React and JavaScript by putting states into objects and updating them all at...
Read more >React state batch updating - reduce re-renders | The Startup
Instead of one by one, React does batch updates, reducing the number of component renders. In this article, we will examine how and...
Read more >React JS, How to only allow component to update once per ...
I want to have Component A only update once per second, as we are using socket IO to update live results, but when...
Read more >5 Ways to Avoid React Component Re-Renderings
In this article, I have discussed 5 different methods to prevent unnecessary re-rendering in React components. Most of these solutions capitalize caching, and ......
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 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
@ianstormtaylor I think the performance of keypress described on this issue was due to the example site was using the dev version of react which has been solved by https://github.com/ianstormtaylor/slate/pull/1939 . The current performance of keypress with production build is now ~40ms instead of ~300ms. Also tested production build of https://github.com/ianstormtaylor/slate/pull/1975 with memoization on slate react seems to reduce it down even further to ~20ms.
perhaps i didn’t make this clear. the onus is on the plugin author. if they don’t want to write that logic, that’s fine. The performance is no worse than it is today.
I listed the exact bottlenecks in the original comment:
I’ve detailed out a plan to avoid those bottlenecks without the need for a breaking change. I don’t know what else I can do.