Skip to content

Commit 7ac8e61

Browse files
authored
Only log component level profiling for components that actually performed work (#31522)
This provides less context but skips a lot of noise. Previously we were including parent components to provide context about what is rendering but this turns out to be: 1) Very expensive due to the overhead of `performance.measure()` while profiling. 2) Unactionable noise in the profile that hurt more than it added in real apps with large trees. This approach instead just add performance.measure calls for each component that was marked as PerformedWork (which was used for this purpose by React Profiler) or had any Effects. Not everything gets marked with PerformedWork though. E.g. DOM nodes do not but they can have significant render times since creating them takes time. We might consider including them if a self-time threshold is met. Because there is little to no context about the component anymore it becomes really essential to get a feature from Chrome DevTools that can link to something with more context like React DevTools.
1 parent 3770c11 commit 7ac8e61

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import {
9797
MaySuspendCommit,
9898
FormReset,
9999
Cloned,
100+
PerformedWork,
100101
} from './ReactFiberFlags';
101102
import {
102103
commitStartTime,
@@ -602,7 +603,8 @@ function commitLayoutEffectOnFiber(
602603
enableComponentPerformanceTrack &&
603604
(finishedWork.mode & ProfileMode) !== NoMode &&
604605
componentEffectStartTime >= 0 &&
605-
componentEffectEndTime >= 0
606+
componentEffectEndTime >= 0 &&
607+
componentEffectDuration > 0.05
606608
) {
607609
logComponentEffect(
608610
finishedWork,
@@ -2106,7 +2108,8 @@ function commitMutationEffectsOnFiber(
21062108
enableComponentPerformanceTrack &&
21072109
(finishedWork.mode & ProfileMode) !== NoMode &&
21082110
componentEffectStartTime >= 0 &&
2109-
componentEffectEndTime >= 0
2111+
componentEffectEndTime >= 0 &&
2112+
componentEffectDuration > 0.05
21102113
) {
21112114
logComponentEffect(
21122115
finishedWork,
@@ -2647,7 +2650,8 @@ function commitPassiveMountOnFiber(
26472650
enableProfilerTimer &&
26482651
enableComponentPerformanceTrack &&
26492652
(finishedWork.mode & ProfileMode) !== NoMode &&
2650-
((finishedWork.actualStartTime: any): number) > 0
2653+
((finishedWork.actualStartTime: any): number) > 0 &&
2654+
(finishedWork.flags & PerformedWork) !== NoFlags
26512655
) {
26522656
logComponentRender(
26532657
finishedWork,
@@ -2929,7 +2933,8 @@ function commitPassiveMountOnFiber(
29292933
enableComponentPerformanceTrack &&
29302934
(finishedWork.mode & ProfileMode) !== NoMode &&
29312935
componentEffectStartTime >= 0 &&
2932-
componentEffectEndTime >= 0
2936+
componentEffectEndTime >= 0 &&
2937+
componentEffectDuration > 0.05
29332938
) {
29342939
logComponentEffect(
29352940
finishedWork,
@@ -3448,7 +3453,8 @@ function commitPassiveUnmountOnFiber(finishedWork: Fiber): void {
34483453
enableComponentPerformanceTrack &&
34493454
(finishedWork.mode & ProfileMode) !== NoMode &&
34503455
componentEffectStartTime >= 0 &&
3451-
componentEffectEndTime >= 0
3456+
componentEffectEndTime >= 0 &&
3457+
componentEffectDuration > 0.05
34523458
) {
34533459
logComponentEffect(
34543460
finishedWork,

0 commit comments

Comments
 (0)