-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
[Fiber] Log Component Renders to Custom Performance Track #30967
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3b80acf
Missing comment
sebmarkbage 632cea8
Always visit nodes that had any actual duration this commit in the pa…
sebmarkbage 598775b
Track complete time
sebmarkbage 1e67729
Pass the endTime recursively through the passive commit phase
sebmarkbage 5545a58
Track startTime of siblings outside of the Profiler mode tree
sebmarkbage c574330
Log start/end time of a Component's render track after it commits
sebmarkbage b03e3ee
Name the track by the committed lanes
sebmarkbage 2a1903d
Feature test
sebmarkbage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
61 changes: 61 additions & 0 deletions
61
packages/react-reconciler/src/ReactFiberPerformanceTrack.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {Fiber} from './ReactInternalTypes'; | ||
|
||
import getComponentNameFromFiber from './getComponentNameFromFiber'; | ||
|
||
import {getGroupNameOfHighestPriorityLane} from './ReactFiberLane'; | ||
|
||
import {enableProfilerTimer} from 'shared/ReactFeatureFlags'; | ||
|
||
const supportsUserTiming = | ||
enableProfilerTimer && | ||
typeof performance !== 'undefined' && | ||
// $FlowFixMe[method-unbinding] | ||
typeof performance.measure === 'function'; | ||
|
||
const TRACK_GROUP = 'Components ⚛'; | ||
|
||
// Reused to avoid thrashing the GC. | ||
const reusableComponentDevToolDetails = { | ||
dataType: 'track-entry', | ||
color: 'primary', | ||
track: 'Blocking', // Lane | ||
trackGroup: TRACK_GROUP, | ||
}; | ||
const reusableComponentOptions = { | ||
start: -0, | ||
end: -0, | ||
detail: { | ||
devtools: reusableComponentDevToolDetails, | ||
}, | ||
}; | ||
|
||
export function setCurrentTrackFromLanes(lanes: number): void { | ||
reusableComponentDevToolDetails.track = | ||
getGroupNameOfHighestPriorityLane(lanes); | ||
} | ||
|
||
export function logComponentRender( | ||
fiber: Fiber, | ||
startTime: number, | ||
endTime: number, | ||
): void { | ||
const name = getComponentNameFromFiber(fiber); | ||
if (name === null) { | ||
// Skip | ||
return; | ||
} | ||
if (supportsUserTiming) { | ||
reusableComponentOptions.start = startTime; | ||
reusableComponentOptions.end = endTime; | ||
performance.measure(name, reusableComponentOptions); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you thinking about splitting 'hidden' out for offscreen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's actually quite a lot of "Idle" work like hydration and the prerender. I think we'll actually put other lanes here too that end up suspending because that work weren't necessarily blocking anything - the suspended thing was.
There's too much nuance to communicate here but the one thing they have in common is that it's not directly connected to an outcome like a navigation. They're all warming up for some future work and so you shouldn't be too concerned about them taking a long time. They're red herrings.