{{ message }}
[react-devtools] add memory profiling tool#36827
Open
ayimdomnic wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR implements Memory Profiling with Automatic Leak Detection for React DevTools, addressing issue #36722.
Motivation
Currently, React DevTools lacks built-in memory profiling capabilities, making it difficult for developers to identify and debug memory leaks in their React applications. Developers must rely on external tools like Chrome DevTools' heap snapshots, which don't provide React-specific insights about component lifecycle issues, detached DOM nodes, or common React patterns that cause leaks.
This feature adds:
Implementation Details
Backend (packages/react-devtools-shared/src/backend/):
memoryProfiler.js(463 lines) - Core profiling engine with Performance API integration, snapshot capture, trend analysis, and growth detectionmemoryLeakDetector.js(461 lines) - Pattern recognition for detached DOM nodes, event listeners, component lifecycle issues, timers, subscriptions, and memory growthprofilingHooks.js- Extended with memory profiling lifecycle hookstypes.js- Added 7 new Flow types:MemoryProfilingData,MemorySnapshot,MemoryTrend,LeakDetectionResult,LeakPattern, etc.bridge.js- Added 4 backend + 4 frontend events for memory profiling communicationData Layer (packages/react-devtools-shared/src/devtools/):
ProfilerStore.js- Extended with memory state management and event listenersMemoryProfilingCache.js(328 lines) - Cached derived data for UI (chart data, statistics, sorted leaks, growth rates)Frontend UI (packages/react-devtools-shared/src/devtools/views/Profiler/):
MemoryProfiler.js(152 lines) - Main container with NoData/Recording/HasData statesMemoryDashboard.js(311 lines) - 8-metric stats grid + SVG line chart for memory trendsMemoryLeakWarnings.js(215 lines) - Leak cards with severity filtering, expandable details, suggestionsMemoryOptimizationSuggestions.js(176 lines) - Dynamically generated fix recommendations with code examplesProfiler.js- Integrated "Memory" tab alongside Flamegraph/Ranked/Timeline tabsTests (packages/react-devtools-shared/src/tests/):
memoryProfiler-test.js(389 lines) - 15+ test suites covering snapshot capture, monitoring, trend analysis, cleanupmemoryLeakDetector-test.js(421 lines) - 20+ test scenarios for all 6 leak detection algorithmsKey Features
performance.memoryfor accurate heap size tracking with graceful degradation when unavailableHow did you test this change?
Static Analysis ✅