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.

Bug: Excessive cpu usage of the page when react-devtools is active

See original GitHub issue

When option “Highlight updates when components render” is activated the whole page repaints in rapid succession after the components state has been changed. It causes 100% CPU usage by the browser and unpleasant DX due low fps.

React version: 16.12.0 DevTools version 4.4.0-f749045a5

The sequance of actions is important:

  1. Open react application
  2. Open react-devtools
  3. Check option “Highlight updates when components render” in react-devtools settings
  4. Change the internal state of a component
  5. In activity monitor there will be 100% cpu usage of the page, or check option “Paint flashing” in rendering pane of chrome devtools

image image

The code example (to trigger the issue: 1) check the option “Highlight updates when components render” and 2) click on the button:

import React, {useState} from 'react';

function App() {
  const [count, setCount] = useState(0);

  return (
    <button onClick={() => setCount(count + 1)}>
      click #{count}
    </button>
  );
}

export default App;

The current behavior

Excessive cpu usage of the page

The expected behavior

Normal cpu usage of the page

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Faelivrinxcommented, Apr 5, 2020

Oh wow. So essentially setTimeout with MAX_VALUE kind of just overflows?

Browsers including Internet Explorer, Chrome, Safari, and Firefox store the delay as a 32-bit signed integer internally. This causes an integer overflow when using delays larger than 2,147,483,647 ms (about 24.8 days), resulting in the timeout being executed immediately. source

I think what the code should do is not call setTimeout when it is still Number.MAX_VALUE because it means we don’t have anything to draw. Or refactor this differently somehow.

Oh, I see. I’ll try to refactor it a little bit but without engaging to refactor other functions. Maybe just reversed conditions will be more readable in this situation.

2reactions
M-Izadmehrcommented, Feb 7, 2020

@mkrl Interesting, I cloned your repository it worked fine for me too, it might be a chrome bug on ubuntu, can you also check it with firefox devtools (it is basically the same code base just built for firefox), if it exists there too it means that it is probably related to react-devtools.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging performance problems in React - LogRocket Blog
Learn how to debug performance problems in React with this post ... is taking too long to process (usually related to CPU consumption)....
Read more >
React - High CPU usage on website idle even when no events ...
Noticed quite high CPU usage, doing some investigation seems like its constantly using on 50% cpu on the chrome task manager.
Read more >
Analyze runtime performance - Chrome Developers
Whenever you profile a page, use CPU Throttling to simulate how your page performs on mobile devices. In DevTools, click the Performance tab....
Read more >
How to track down CPU issues in Node.js | Dynatrace news
Let's find out what causes very high Node.js CPU usage! ... here's a story by Netflix on how they used flame charts to...
Read more >
High CPU usage because of service worker (sw.js)
To test weather the recent update has been causing the issue, you could (1) remove all extensions, (2) unregister all service workers through ......
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