Skip to content

[Fiber] Log the Render/Commit phases and the gaps in between #31016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions packages/react-reconciler/src/ReactFiberCommitEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ function safelyCallDestroy(
function commitProfiler(
finishedWork: Fiber,
current: Fiber | null,
commitTime: number,
commitStartTime: number,
effectDuration: number,
) {
const {id, onCommit, onRender} = finishedWork.memoizedProps;
Expand All @@ -918,7 +918,7 @@ function commitProfiler(
finishedWork.actualDuration,
finishedWork.treeBaseDuration,
finishedWork.actualStartTime,
commitTime,
commitStartTime,
);
}

Expand All @@ -928,7 +928,7 @@ function commitProfiler(
finishedWork.memoizedProps.id,
phase,
effectDuration,
commitTime,
commitStartTime,
);
}
}
Expand All @@ -937,7 +937,7 @@ function commitProfiler(
export function commitProfilerUpdate(
finishedWork: Fiber,
current: Fiber | null,
commitTime: number,
commitStartTime: number,
effectDuration: number,
) {
if (enableProfilerTimer) {
Expand All @@ -948,11 +948,11 @@ export function commitProfilerUpdate(
commitProfiler,
finishedWork,
current,
commitTime,
commitStartTime,
effectDuration,
);
} else {
commitProfiler(finishedWork, current, commitTime, effectDuration);
commitProfiler(finishedWork, current, commitStartTime, effectDuration);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
Expand All @@ -963,7 +963,7 @@ export function commitProfilerUpdate(
function commitProfilerPostCommitImpl(
finishedWork: Fiber,
current: Fiber | null,
commitTime: number,
commitStartTime: number,
passiveEffectDuration: number,
): void {
const {id, onPostCommit} = finishedWork.memoizedProps;
Expand All @@ -976,14 +976,14 @@ function commitProfilerPostCommitImpl(
}

if (typeof onPostCommit === 'function') {
onPostCommit(id, phase, passiveEffectDuration, commitTime);
onPostCommit(id, phase, passiveEffectDuration, commitStartTime);
}
}

export function commitProfilerPostCommit(
finishedWork: Fiber,
current: Fiber | null,
commitTime: number,
commitStartTime: number,
passiveEffectDuration: number,
) {
try {
Expand All @@ -993,14 +993,14 @@ export function commitProfilerPostCommit(
commitProfilerPostCommitImpl,
finishedWork,
current,
commitTime,
commitStartTime,
passiveEffectDuration,
);
} else {
commitProfilerPostCommitImpl(
finishedWork,
current,
commitTime,
commitStartTime,
passiveEffectDuration,
);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ import {
Cloned,
} from './ReactFiberFlags';
import {
commitTime,
completeTime,
commitStartTime,
pushNestedEffectDurations,
popNestedEffectDurations,
bubbleNestedEffectDurations,
Expand Down Expand Up @@ -505,7 +504,7 @@ function commitLayoutEffectOnFiber(
commitProfilerUpdate(
finishedWork,
current,
commitTime,
commitStartTime,
profilerInstance.effectDuration,
);
} else {
Expand Down Expand Up @@ -2345,7 +2344,7 @@ export function reappearLayoutEffects(
commitProfilerUpdate(
finishedWork,
current,
commitTime,
commitStartTime,
profilerInstance.effectDuration,
);
} else {
Expand Down Expand Up @@ -2568,6 +2567,7 @@ export function commitPassiveMountEffects(
finishedWork: Fiber,
committedLanes: Lanes,
committedTransitions: Array<Transition> | null,
renderEndTime: number, // Profiling-only
): void {
resetComponentEffectTimers();

Expand All @@ -2576,7 +2576,7 @@ export function commitPassiveMountEffects(
finishedWork,
committedLanes,
committedTransitions,
enableProfilerTimer && enableComponentPerformanceTrack ? completeTime : 0,
enableProfilerTimer && enableComponentPerformanceTrack ? renderEndTime : 0,
);
}

Expand Down Expand Up @@ -2763,7 +2763,7 @@ function commitPassiveMountOnFiber(
finishedWork.alternate,
// This value will still reflect the previous commit phase.
// It does not get reset until the start of the next commit phase.
commitTime,
commitStartTime,
profilerInstance.passiveEffectDuration,
);
} else {
Expand Down
65 changes: 65 additions & 0 deletions packages/react-reconciler/src/ReactFiberPerformanceTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,68 @@ export function logTransitionStart(
}
}
}

export function logRenderPhase(startTime: number, endTime: number): void {
if (supportsUserTiming) {
reusableComponentDevToolDetails.color = 'primary-dark';
reusableComponentOptions.start = startTime;
reusableComponentOptions.end = endTime;
performance.measure('Render', reusableComponentOptions);
}
}

export function logSuspenseThrottlePhase(
startTime: number,
endTime: number,
): void {
// This was inside a throttled Suspense boundary commit.
if (supportsUserTiming) {
reusableComponentDevToolDetails.color = 'secondary-light';
reusableComponentOptions.start = startTime;
reusableComponentOptions.end = endTime;
performance.measure('Throttled', reusableComponentOptions);
}
}

export function logSuspendedCommitPhase(
startTime: number,
endTime: number,
): void {
// This means the commit was suspended on CSS or images.
if (supportsUserTiming) {
reusableComponentDevToolDetails.color = 'secondary-light';
reusableComponentOptions.start = startTime;
reusableComponentOptions.end = endTime;
performance.measure('Suspended', reusableComponentOptions);
}
}

export function logCommitPhase(startTime: number, endTime: number): void {
if (supportsUserTiming) {
reusableComponentDevToolDetails.color = 'secondary-dark';
reusableComponentOptions.start = startTime;
reusableComponentOptions.end = endTime;
performance.measure('Commit', reusableComponentOptions);
}
}

export function logPaintYieldPhase(startTime: number, endTime: number): void {
if (supportsUserTiming) {
reusableComponentDevToolDetails.color = 'secondary-light';
reusableComponentOptions.start = startTime;
reusableComponentOptions.end = endTime;
performance.measure('Waiting for Paint', reusableComponentOptions);
}
}

export function logPassiveCommitPhase(
startTime: number,
endTime: number,
): void {
if (supportsUserTiming) {
reusableComponentDevToolDetails.color = 'secondary-dark';
reusableComponentOptions.start = startTime;
reusableComponentOptions.end = endTime;
performance.measure('Remaining Effects', reusableComponentOptions);
}
}
Loading
Loading