[DevTools] Fix high CPU usage on pages without React (#35515)#35516
[DevTools] Fix high CPU usage on pages without React (#35515)#35516CarlosEduJs wants to merge 2 commits intofacebook:mainfrom
Conversation
Stop polling for React after 10 attempts (~5 seconds) to prevent infinite loop of 'hello' messages on pages without React. Fixes facebook#35515
|
Hi @CarlosEduJs! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
The retry limiter definitely helps, it makes the extension way less eager to scream “hello???” forever and burn CPUs. So the PR has real value as a safety valve for people browsing heavy sites (Google, dashboards, etc.). But the core issue is architectural: DevTools does active polling over a wide-open postMessage channel with no strict origin/protocol validation. On complex pages that relay messages (iframes, sandboxed scripts, whatever), you can end up with feedback loops that keep waking the handshake logic even after retries stop. So limiting retries = good bandaid, but long-term fix needs a more robust handshake mechanism. I'm also looking into more robust long-term approaches. |
Replaces the polling mechanism in proxy.js with an event-driven approach. backendManager.js now dispatches a 'react-devtools-ready' event and sets a data attribute when initialized. This eliminates CPU usage on non-React pages by removing the need for a polling loop.
Update: I've refactored the fix to address the root cause instead of just limiting retries.
Passive Signaling:
Non-React Pages: Zero code execution loop, resulting in 0% CPU overhead and no console noise. |
Summary
Fixes high CPU usage in React DevTools when browsing pages without React (e.g., Google Search results).
Motivation: The content script was polling indefinitely with setInterval, sending "hello" messages every 500ms to detect React. On pages without React, this loop never stopped, causing high CPU usage and battery drain.
Solution: Added a maximum retry limit of 10 attempts (~5 seconds). After this timeout, the polling stops automatically on pages without React, while still allowing enough time for slow-loading React apps to initialize.
How did you test this change?
Manual Testing
Built and tested the extension on both Chrome and Firefox:
Chrome:
Firefox:
Results
Before fix:
After fix:
Screenshot:

Checklist
Related Issue