Skip to content

Commit 214697b

Browse files
committed
Move renderStartTime and renderEndTime to the commit closure
Since multiple roots can start rendering and overriding these while the commit is still pending. Then we need to stash it temporarily on module scope for the passive effect. Same as lanes.
1 parent c540e55 commit 214697b

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ import {
100100
} from './ReactFiberFlags';
101101
import {
102102
commitStartTime,
103-
renderEndTime,
104103
pushNestedEffectDurations,
105104
popNestedEffectDurations,
106105
bubbleNestedEffectDurations,
@@ -2568,6 +2567,7 @@ export function commitPassiveMountEffects(
25682567
finishedWork: Fiber,
25692568
committedLanes: Lanes,
25702569
committedTransitions: Array<Transition> | null,
2570+
renderEndTime: number, // Profiling-only
25712571
): void {
25722572
resetComponentEffectTimers();
25732573

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,9 @@ import {
245245
clampTransitionTimers,
246246
markNestedUpdateScheduled,
247247
renderStartTime,
248-
renderEndTime,
249248
commitStartTime,
250249
commitEndTime,
251250
recordRenderTime,
252-
recordCompleteTime,
253251
recordCommitTime,
254252
recordCommitEndTime,
255253
resetNestedUpdateFlag,
@@ -611,6 +609,7 @@ let rootDoesHavePassiveEffects: boolean = false;
611609
let rootWithPendingPassiveEffects: FiberRoot | null = null;
612610
let pendingPassiveEffectsLanes: Lanes = NoLanes;
613611
let pendingPassiveEffectsRemainingLanes: Lanes = NoLanes;
612+
let pendingPassiveEffectsRenderEndTime: number = -0; // Profiling-only
614613
let pendingPassiveTransitions: Array<Transition> | null = null;
615614

616615
// Use these to prevent an infinite loop of nested updates
@@ -1129,10 +1128,11 @@ function finishConcurrentRender(
11291128
finishedWork: Fiber,
11301129
lanes: Lanes,
11311130
) {
1131+
let renderEndTime = 0;
11321132
if (enableProfilerTimer && enableComponentPerformanceTrack) {
11331133
// Track when we finished the last unit of work, before we actually commit it.
11341134
// The commit can be suspended/blocked until we commit it.
1135-
recordCompleteTime();
1135+
renderEndTime = now();
11361136
setCurrentTrackFromLanes(lanes);
11371137
logRenderPhase(renderStartTime, renderEndTime);
11381138
}
@@ -1195,6 +1195,8 @@ function finishConcurrentRender(
11951195
workInProgressRootInterleavedUpdatedLanes,
11961196
workInProgressSuspendedRetryLanes,
11971197
IMMEDIATE_COMMIT,
1198+
renderStartTime,
1199+
renderEndTime,
11981200
);
11991201
} else {
12001202
if (
@@ -1241,6 +1243,8 @@ function finishConcurrentRender(
12411243
workInProgressSuspendedRetryLanes,
12421244
workInProgressRootDidSkipSuspendedSiblings,
12431245
THROTTLED_COMMIT,
1246+
renderStartTime,
1247+
renderEndTime,
12441248
),
12451249
msUntilTimeout,
12461250
);
@@ -1259,6 +1263,8 @@ function finishConcurrentRender(
12591263
workInProgressSuspendedRetryLanes,
12601264
workInProgressRootDidSkipSuspendedSiblings,
12611265
IMMEDIATE_COMMIT,
1266+
renderStartTime,
1267+
renderEndTime,
12621268
);
12631269
}
12641270
}
@@ -1274,7 +1280,9 @@ function commitRootWhenReady(
12741280
updatedLanes: Lanes,
12751281
suspendedRetryLanes: Lanes,
12761282
didSkipSuspendedSiblings: boolean,
1277-
suspendedCommitReason: SuspendedCommitReason,
1283+
suspendedCommitReason: SuspendedCommitReason, // Profiling-only
1284+
completedRenderStartTime: number, // Profiling-only
1285+
completedRenderEndTime: number, // Profiling-only
12781286
) {
12791287
// TODO: Combine retry throttling with Suspensey commits. Right now they run
12801288
// one after the other.
@@ -1333,6 +1341,8 @@ function commitRootWhenReady(
13331341
updatedLanes,
13341342
suspendedRetryLanes,
13351343
suspendedCommitReason,
1344+
completedRenderStartTime,
1345+
completedRenderEndTime,
13361346
);
13371347
}
13381348

@@ -1524,8 +1534,9 @@ export function performSyncWorkOnRoot(root: FiberRoot, lanes: Lanes): null {
15241534
return null;
15251535
}
15261536

1537+
let renderEndTime = 0;
15271538
if (enableProfilerTimer && enableComponentPerformanceTrack) {
1528-
recordCompleteTime();
1539+
renderEndTime = now();
15291540
setCurrentTrackFromLanes(lanes);
15301541
logRenderPhase(renderStartTime, renderEndTime);
15311542
}
@@ -1544,6 +1555,8 @@ export function performSyncWorkOnRoot(root: FiberRoot, lanes: Lanes): null {
15441555
workInProgressRootInterleavedUpdatedLanes,
15451556
workInProgressSuspendedRetryLanes,
15461557
IMMEDIATE_COMMIT,
1558+
renderStartTime,
1559+
renderEndTime,
15471560
);
15481561

15491562
// Before exiting, make sure there's a callback scheduled for the next
@@ -3050,7 +3063,9 @@ function commitRoot(
30503063
spawnedLane: Lane,
30513064
updatedLanes: Lanes,
30523065
suspendedRetryLanes: Lanes,
3053-
suspendedCommitReason: SuspendedCommitReason,
3066+
suspendedCommitReason: SuspendedCommitReason, // Profiling-only
3067+
completedRenderStartTime: number, // Profiling-only
3068+
completedRenderEndTime: number, // Profiling-only
30543069
) {
30553070
// TODO: This no longer makes any sense. We already wrap the mutation and
30563071
// layout phases. Should be able to remove.
@@ -3069,6 +3084,8 @@ function commitRoot(
30693084
updatedLanes,
30703085
suspendedRetryLanes,
30713086
suspendedCommitReason,
3087+
completedRenderStartTime,
3088+
completedRenderEndTime,
30723089
);
30733090
} finally {
30743091
ReactSharedInternals.T = prevTransition;
@@ -3087,7 +3104,9 @@ function commitRootImpl(
30873104
spawnedLane: Lane,
30883105
updatedLanes: Lanes,
30893106
suspendedRetryLanes: Lanes,
3090-
suspendedCommitReason: SuspendedCommitReason,
3107+
suspendedCommitReason: SuspendedCommitReason, // Profiling-only
3108+
completedRenderStartTime: number, // Profiling-only
3109+
completedRenderEndTime: number, // Profiling-only
30913110
) {
30923111
do {
30933112
// `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
@@ -3203,6 +3222,7 @@ function commitRootImpl(
32033222
if (!rootDoesHavePassiveEffects) {
32043223
rootDoesHavePassiveEffects = true;
32053224
pendingPassiveEffectsRemainingLanes = remainingLanes;
3225+
pendingPassiveEffectsRenderEndTime = completedRenderEndTime;
32063226
// workInProgressTransitions might be overwritten, so we want
32073227
// to store it in pendingPassiveTransitions until they get processed
32083228
// We need to pass this through as an argument to commitRoot
@@ -3226,9 +3246,9 @@ function commitRootImpl(
32263246
recordCommitTime();
32273247
if (enableComponentPerformanceTrack) {
32283248
if (suspendedCommitReason === SUSPENDED_COMMIT) {
3229-
logSuspendedCommitPhase(renderEndTime, commitStartTime);
3249+
logSuspendedCommitPhase(completedRenderEndTime, commitStartTime);
32303250
} else if (suspendedCommitReason === THROTTLED_COMMIT) {
3231-
logSuspenseThrottlePhase(renderEndTime, commitStartTime);
3251+
logSuspenseThrottlePhase(completedRenderEndTime, commitStartTime);
32323252
}
32333253
}
32343254
}
@@ -3628,7 +3648,13 @@ function flushPassiveEffectsImpl(wasDelayedCommit: void | boolean) {
36283648
executionContext |= CommitContext;
36293649

36303650
commitPassiveUnmountEffects(root.current);
3631-
commitPassiveMountEffects(root, root.current, lanes, transitions);
3651+
commitPassiveMountEffects(
3652+
root,
3653+
root.current,
3654+
lanes,
3655+
transitions,
3656+
pendingPassiveEffectsRenderEndTime,
3657+
);
36323658

36333659
if (__DEV__) {
36343660
if (enableDebugTracing) {

packages/react-reconciler/src/ReactProfilerTimer.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import * as Scheduler from 'scheduler';
2828
const {unstable_now: now} = Scheduler;
2929

3030
export let renderStartTime: number = -0;
31-
export let renderEndTime: number = -0;
3231
export let commitStartTime: number = -0;
3332
export let commitEndTime: number = -0;
3433
export let profilerStartTime: number = -1.1;
@@ -256,13 +255,6 @@ export function recordRenderTime(): void {
256255
renderStartTime = now();
257256
}
258257

259-
export function recordCompleteTime(): void {
260-
if (!enableProfilerTimer) {
261-
return;
262-
}
263-
renderEndTime = now();
264-
}
265-
266258
export function recordCommitTime(): void {
267259
if (!enableProfilerTimer) {
268260
return;

0 commit comments

Comments
 (0)