-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
[Flight] Emit Deduped Server Components Marker #31737
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -72,6 +72,7 @@ import {readTemporaryReference} from './ReactFlightTemporaryReferences'; | |||||
import { | ||||||
markAllTracksInOrder, | ||||||
logComponentRender, | ||||||
logDedupedComponentRender, | ||||||
} from './ReactFlightPerformanceTrack'; | ||||||
|
||||||
import { | ||||||
|
@@ -130,6 +131,7 @@ export type JSONValue = | |||||
type ProfilingResult = { | ||||||
track: number, | ||||||
endTime: number, | ||||||
component: null | ReactComponentInfo, | ||||||
}; | ||||||
|
||||||
const ROW_ID = 0; | ||||||
|
@@ -647,7 +649,7 @@ export function reportGlobalError(response: Response, error: Error): void { | |||||
}); | ||||||
if (enableProfilerTimer && enableComponentPerformanceTrack) { | ||||||
markAllTracksInOrder(); | ||||||
flushComponentPerformance(getChunk(response, 0), 0, -Infinity); | ||||||
flushComponentPerformance(getChunk(response, 0), 0, -Infinity, -Infinity); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I originally had that but it's not quite right because Another consideration is that |
||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -2748,7 +2750,8 @@ function resolveTypedArray( | |||||
function flushComponentPerformance( | ||||||
root: SomeChunk<any>, | ||||||
trackIdx: number, // Next available track | ||||||
trackTime: number, // The time after which it is available | ||||||
trackTime: number, // The time after which it is available, | ||||||
parentEndTime: number, | ||||||
): ProfilingResult { | ||||||
if (!enableProfilerTimer || !enableComponentPerformanceTrack) { | ||||||
// eslint-disable-next-line react-internal/prod-error-codes | ||||||
|
@@ -2765,6 +2768,22 @@ function flushComponentPerformance( | |||||
// chunk in two places. We should extend the current end time as if it was | ||||||
// rendered as part of this tree. | ||||||
const previousResult: ProfilingResult = root._children; | ||||||
const previousEndTime = previousResult.endTime; | ||||||
if ( | ||||||
parentEndTime > -Infinity && | ||||||
parentEndTime < previousEndTime && | ||||||
previousResult.component !== null | ||||||
) { | ||||||
// Log a placeholder for the deduped value under this child starting | ||||||
// from the end of the self time of the parent and spanning until the | ||||||
// the deduped end. | ||||||
logDedupedComponentRender( | ||||||
previousResult.component, | ||||||
trackIdx, | ||||||
parentEndTime, | ||||||
previousEndTime, | ||||||
); | ||||||
} | ||||||
// Since we didn't bump the track this time, we just return the same track. | ||||||
previousResult.track = trackIdx; | ||||||
return previousResult; | ||||||
|
@@ -2792,15 +2811,27 @@ function flushComponentPerformance( | |||||
// The start time of this component is before the end time of the previous | ||||||
// component on this track so we need to bump the next one to a parallel track. | ||||||
trackIdx++; | ||||||
trackTime = startTime; | ||||||
} | ||||||
trackTime = startTime; | ||||||
break; | ||||||
} | ||||||
} | ||||||
} | ||||||
for (let i = debugInfo.length - 1; i >= 0; i--) { | ||||||
const info = debugInfo[i]; | ||||||
if (typeof info.time === 'number') { | ||||||
if (info.time > parentEndTime) { | ||||||
parentEndTime = info.time; | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
const result: ProfilingResult = {track: trackIdx, endTime: -Infinity}; | ||||||
const result: ProfilingResult = { | ||||||
track: trackIdx, | ||||||
endTime: -Infinity, | ||||||
component: null, | ||||||
}; | ||||||
root._children = result; | ||||||
let childrenEndTime = -Infinity; | ||||||
let childTrackIdx = trackIdx; | ||||||
|
@@ -2810,7 +2841,11 @@ function flushComponentPerformance( | |||||
children[i], | ||||||
childTrackIdx, | ||||||
childTrackTime, | ||||||
parentEndTime, | ||||||
); | ||||||
if (childResult.component !== null) { | ||||||
result.component = childResult.component; | ||||||
} | ||||||
childTrackIdx = childResult.track; | ||||||
const childEndTime = childResult.endTime; | ||||||
childTrackTime = childEndTime; | ||||||
|
@@ -2842,6 +2877,8 @@ function flushComponentPerformance( | |||||
endTime, | ||||||
childrenEndTime, | ||||||
); | ||||||
// Track the root most component of the result for deduping logging. | ||||||
result.component = componentInfo; | ||||||
} | ||||||
} | ||||||
} | ||||||
|
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.
I had to add this hack because there's an unrelated bug that cause debug info to shift order when the props are delayed.
react/packages/react-client/src/ReactFlightClient.js
Line 2842 in a496498