Skip to content

Commit 69e5990

Browse files
committed
Log component render timings for reconnected and already offscreen offscreen subtrees
1 parent 6fc6f7a commit 69e5990

File tree

2 files changed

+99
-16
lines changed

2 files changed

+99
-16
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 98 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,7 @@ function commitPassiveMountOnFiber(
28962896
finishedWork,
28972897
committedLanes,
28982898
committedTransitions,
2899+
endTime,
28992900
);
29002901
}
29012902
} else {
@@ -2935,6 +2936,7 @@ function commitPassiveMountOnFiber(
29352936
committedLanes,
29362937
committedTransitions,
29372938
includeWorkInProgressEffects,
2939+
endTime,
29382940
);
29392941
}
29402942
}
@@ -3014,6 +3016,7 @@ function recursivelyTraverseReconnectPassiveEffects(
30143016
committedLanes: Lanes,
30153017
committedTransitions: Array<Transition> | null,
30163018
includeWorkInProgressEffects: boolean,
3019+
endTime: number,
30173020
) {
30183021
// This function visits both newly finished work and nodes that were re-used
30193022
// from a previously committed tree. We cannot check non-static flags if the
@@ -3025,14 +3028,30 @@ function recursivelyTraverseReconnectPassiveEffects(
30253028
// TODO (Offscreen) Check: flags & (RefStatic | LayoutStatic)
30263029
let child = parentFiber.child;
30273030
while (child !== null) {
3028-
reconnectPassiveEffects(
3029-
finishedRoot,
3030-
child,
3031-
committedLanes,
3032-
committedTransitions,
3033-
childShouldIncludeWorkInProgressEffects,
3034-
);
3035-
child = child.sibling;
3031+
if (enableProfilerTimer && enableComponentPerformanceTrack) {
3032+
const nextSibling = child.sibling;
3033+
reconnectPassiveEffects(
3034+
finishedRoot,
3035+
child,
3036+
committedLanes,
3037+
committedTransitions,
3038+
childShouldIncludeWorkInProgressEffects,
3039+
nextSibling !== null
3040+
? ((nextSibling.actualStartTime: any): number)
3041+
: endTime,
3042+
);
3043+
child = nextSibling;
3044+
} else {
3045+
reconnectPassiveEffects(
3046+
finishedRoot,
3047+
child,
3048+
committedLanes,
3049+
committedTransitions,
3050+
childShouldIncludeWorkInProgressEffects,
3051+
endTime,
3052+
);
3053+
child = child.sibling;
3054+
}
30363055
}
30373056
}
30383057

@@ -3045,9 +3064,28 @@ export function reconnectPassiveEffects(
30453064
// from a previously committed tree. We cannot check non-static flags if the
30463065
// node was reused.
30473066
includeWorkInProgressEffects: boolean,
3067+
endTime: number, // Profiling-only. The start time of the next Fiber or root completion.
30483068
) {
30493069
const prevEffectStart = pushComponentEffectStart();
30503070

3071+
// If this component rendered in Profiling mode (DEV or in Profiler component) then log its
3072+
// render time. We do this after the fact in the passive effect to avoid the overhead of this
3073+
// getting in the way of the render characteristics and avoid the overhead of unwinding
3074+
// uncommitted renders.
3075+
if (
3076+
enableProfilerTimer &&
3077+
enableComponentPerformanceTrack &&
3078+
(finishedWork.mode & ProfileMode) !== NoMode &&
3079+
((finishedWork.actualStartTime: any): number) > 0 &&
3080+
(finishedWork.flags & PerformedWork) !== NoFlags
3081+
) {
3082+
logComponentRender(
3083+
finishedWork,
3084+
((finishedWork.actualStartTime: any): number),
3085+
endTime,
3086+
);
3087+
}
3088+
30513089
const flags = finishedWork.flags;
30523090
switch (finishedWork.tag) {
30533091
case FunctionComponent:
@@ -3059,6 +3097,7 @@ export function reconnectPassiveEffects(
30593097
committedLanes,
30603098
committedTransitions,
30613099
includeWorkInProgressEffects,
3100+
endTime,
30623101
);
30633102
// TODO: Check for PassiveStatic flag
30643103
commitHookPassiveMountEffects(finishedWork, HookPassive);
@@ -3078,6 +3117,7 @@ export function reconnectPassiveEffects(
30783117
committedLanes,
30793118
committedTransitions,
30803119
includeWorkInProgressEffects,
3120+
endTime,
30813121
);
30823122

30833123
if (includeWorkInProgressEffects && flags & Passive) {
@@ -3104,6 +3144,7 @@ export function reconnectPassiveEffects(
31043144
committedLanes,
31053145
committedTransitions,
31063146
includeWorkInProgressEffects,
3147+
endTime,
31073148
);
31083149
} else {
31093150
if (disableLegacyMode || finishedWork.mode & ConcurrentMode) {
@@ -3118,6 +3159,7 @@ export function reconnectPassiveEffects(
31183159
finishedWork,
31193160
committedLanes,
31203161
committedTransitions,
3162+
endTime,
31213163
);
31223164
}
31233165
} else {
@@ -3129,6 +3171,7 @@ export function reconnectPassiveEffects(
31293171
committedLanes,
31303172
committedTransitions,
31313173
includeWorkInProgressEffects,
3174+
endTime,
31323175
);
31333176
}
31343177
}
@@ -3148,6 +3191,7 @@ export function reconnectPassiveEffects(
31483191
committedLanes,
31493192
committedTransitions,
31503193
includeWorkInProgressEffects,
3194+
endTime,
31513195
);
31523196
}
31533197

@@ -3165,6 +3209,7 @@ export function reconnectPassiveEffects(
31653209
committedLanes,
31663210
committedTransitions,
31673211
includeWorkInProgressEffects,
3212+
endTime,
31683213
);
31693214
if (includeWorkInProgressEffects && flags & Passive) {
31703215
// TODO: Pass `current` as argument to this function
@@ -3181,6 +3226,7 @@ export function reconnectPassiveEffects(
31813226
committedLanes,
31823227
committedTransitions,
31833228
includeWorkInProgressEffects,
3229+
endTime,
31843230
);
31853231
if (includeWorkInProgressEffects && flags & Passive) {
31863232
commitTracingMarkerPassiveMountEffect(finishedWork);
@@ -3196,6 +3242,7 @@ export function reconnectPassiveEffects(
31963242
committedLanes,
31973243
committedTransitions,
31983244
includeWorkInProgressEffects,
3245+
endTime,
31993246
);
32003247
break;
32013248
}
@@ -3226,6 +3273,7 @@ function recursivelyTraverseAtomicPassiveEffects(
32263273
parentFiber: Fiber,
32273274
committedLanes: Lanes,
32283275
committedTransitions: Array<Transition> | null,
3276+
endTime: number, // Profiling-only. The start time of the next Fiber or root completion.
32293277
) {
32303278
// "Atomic" effects are ones that need to fire on every commit, even during
32313279
// pre-rendering. We call this function when traversing a hidden tree whose
@@ -3234,13 +3282,28 @@ function recursivelyTraverseAtomicPassiveEffects(
32343282
if (parentFiber.subtreeFlags & PassiveMask) {
32353283
let child = parentFiber.child;
32363284
while (child !== null) {
3237-
commitAtomicPassiveEffects(
3238-
finishedRoot,
3239-
child,
3240-
committedLanes,
3241-
committedTransitions,
3242-
);
3243-
child = child.sibling;
3285+
if (enableProfilerTimer && enableComponentPerformanceTrack) {
3286+
const nextSibling = child.sibling;
3287+
commitAtomicPassiveEffects(
3288+
finishedRoot,
3289+
child,
3290+
committedLanes,
3291+
committedTransitions,
3292+
nextSibling !== null
3293+
? ((nextSibling.actualStartTime: any): number)
3294+
: endTime,
3295+
);
3296+
child = nextSibling;
3297+
} else {
3298+
commitAtomicPassiveEffects(
3299+
finishedRoot,
3300+
child,
3301+
committedLanes,
3302+
committedTransitions,
3303+
endTime,
3304+
);
3305+
child = child.sibling;
3306+
}
32443307
}
32453308
}
32463309
}
@@ -3250,7 +3313,24 @@ function commitAtomicPassiveEffects(
32503313
finishedWork: Fiber,
32513314
committedLanes: Lanes,
32523315
committedTransitions: Array<Transition> | null,
3316+
endTime: number, // Profiling-only. The start time of the next Fiber or root completion.
32533317
) {
3318+
// If this component rendered in Profiling mode (DEV or in Profiler component) then log its
3319+
// render time. A render can happen even if the subtree is offscreen.
3320+
if (
3321+
enableProfilerTimer &&
3322+
enableComponentPerformanceTrack &&
3323+
(finishedWork.mode & ProfileMode) !== NoMode &&
3324+
((finishedWork.actualStartTime: any): number) > 0 &&
3325+
(finishedWork.flags & PerformedWork) !== NoFlags
3326+
) {
3327+
logComponentRender(
3328+
finishedWork,
3329+
((finishedWork.actualStartTime: any): number),
3330+
endTime,
3331+
);
3332+
}
3333+
32543334
// "Atomic" effects are ones that need to fire on every commit, even during
32553335
// pre-rendering. We call this function when traversing a hidden tree whose
32563336
// regular effects are currently disconnected.
@@ -3262,6 +3342,7 @@ function commitAtomicPassiveEffects(
32623342
finishedWork,
32633343
committedLanes,
32643344
committedTransitions,
3345+
endTime,
32653346
);
32663347
if (flags & Passive) {
32673348
// TODO: Pass `current` as argument to this function
@@ -3277,6 +3358,7 @@ function commitAtomicPassiveEffects(
32773358
finishedWork,
32783359
committedLanes,
32793360
committedTransitions,
3361+
endTime,
32803362
);
32813363
if (flags & Passive) {
32823364
// TODO: Pass `current` as argument to this function
@@ -3291,6 +3373,7 @@ function commitAtomicPassiveEffects(
32913373
finishedWork,
32923374
committedLanes,
32933375
committedTransitions,
3376+
endTime,
32943377
);
32953378
break;
32963379
}

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4191,7 +4191,7 @@ function doubleInvokeEffectsOnFiber(
41914191
}
41924192
reappearLayoutEffects(root, fiber.alternate, fiber, false);
41934193
if (shouldDoubleInvokePassiveEffects) {
4194-
reconnectPassiveEffects(root, fiber, NoLanes, null, false);
4194+
reconnectPassiveEffects(root, fiber, NoLanes, null, false, 0);
41954195
}
41964196
} finally {
41974197
setIsStrictModeForDevtools(false);

0 commit comments

Comments
 (0)