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.

Reduce number of component updates

See original GitHub issue

Do 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) badslate

Compare that to the exact same document, but without updates propagated through react. It’s <100ms: better

Proposal:

(Re)introduce selective rendering logic.

As I understand it, here’s the current flow:

  1. key event
  2. add OT to the queue
  3. flush the OT queue
  4. update the component via setState
  5. react updates DOM (EXPENSIVE)
  6. reset scroll & selection range via cDU (EXPENSIVE)

Here’s an improved flow:

  1. key event
  2. 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
  3. flush the OT queue
  4. update the component via setState
  5. use shouldComponentUpdate = () => value.get(pushUpdate)
  6. 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:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
isubasticommented, Jul 17, 2018

@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.

2reactions
mattkrickcommented, Jul 2, 2018

maybe, but that just forces the user to end up writing and managing incredibly complex diffing logic themselves

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.

Feel free to open new issues with specific actionable items for which parts of rendering are slow and could be avoided.

I listed the exact bottlenecks in the original comment:

  1. react updates DOM (EXPENSIVE)
  2. reset scroll & selection range via cDU (EXPENSIVE)

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.

Read more comments on GitHub >

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

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