-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Scheduling Profiler: De-emphasize React internal frames #22588
Merged
bvaughn
merged 3 commits into
facebook:main
from
bvaughn:scheduling-profiler-filter-internal-frames
Oct 21, 2021
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import type { | |
Flamechart, | ||
FlamechartStackFrame, | ||
FlamechartStackLayer, | ||
InternalModuleSourceToRanges, | ||
} from '../types'; | ||
import type { | ||
Interaction, | ||
|
@@ -20,6 +21,11 @@ import type { | |
ViewRefs, | ||
} from '../view-base'; | ||
|
||
import { | ||
CHROME_WEBSTORE_EXTENSION_ID, | ||
INTERNAL_EXTENSION_ID, | ||
LOCAL_EXTENSION_ID, | ||
} from 'react-devtools-shared/src/constants'; | ||
import { | ||
BackgroundColorView, | ||
Surface, | ||
|
@@ -69,13 +75,65 @@ function hoverColorForStackFrame(stackFrame: FlamechartStackFrame): string { | |
return hslaColorToString(color); | ||
} | ||
|
||
function isInternalModule( | ||
internalModuleSourceToRanges: InternalModuleSourceToRanges, | ||
flamechartStackFrame: FlamechartStackFrame, | ||
): boolean { | ||
const {locationColumn, locationLine, scriptUrl} = flamechartStackFrame; | ||
|
||
if (scriptUrl == null || locationColumn == null || locationLine == null) { | ||
return true; | ||
} | ||
|
||
// Internal modules are only registered if DevTools was running when the profile was captured, | ||
// but DevTools should also hide its own frames to avoid over-emphasizing them. | ||
if ( | ||
// Handle webpack-internal:// sources | ||
scriptUrl.includes('/react-devtools') || | ||
scriptUrl.includes('/react_devtools') || | ||
// Filter out known extension IDs | ||
scriptUrl.includes(CHROME_WEBSTORE_EXTENSION_ID) || | ||
scriptUrl.includes(INTERNAL_EXTENSION_ID) || | ||
scriptUrl.includes(LOCAL_EXTENSION_ID) | ||
|
||
// Unfortunately this won't get everything, like relatively loaded chunks or Web Worker files. | ||
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. Open for suggestions here, although doesn't seem like a blocker. |
||
) { | ||
return true; | ||
} | ||
|
||
// Filter out React internal packages. | ||
const ranges = internalModuleSourceToRanges.get(scriptUrl); | ||
bvaughn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (ranges != null) { | ||
for (let i = 0; i < ranges.length; i++) { | ||
const [startStackFrame, stopStackFrame] = ranges[i]; | ||
|
||
const isAfterStart = | ||
locationLine > startStackFrame.lineNumber || | ||
(locationLine === startStackFrame.lineNumber && | ||
locationColumn >= startStackFrame.columnNumber); | ||
const isBeforeStop = | ||
locationLine < stopStackFrame.lineNumber || | ||
(locationLine === stopStackFrame.lineNumber && | ||
locationColumn <= stopStackFrame.columnNumber); | ||
|
||
if (isAfterStart && isBeforeStop) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
class FlamechartStackLayerView extends View { | ||
/** Layer to display */ | ||
_stackLayer: FlamechartStackLayer; | ||
|
||
/** A set of `stackLayer`'s frames, for efficient lookup. */ | ||
_stackFrameSet: Set<FlamechartStackFrame>; | ||
|
||
_internalModuleSourceToRanges: InternalModuleSourceToRanges; | ||
|
||
_intrinsicSize: Size; | ||
|
||
_hoveredStackFrame: FlamechartStackFrame | null = null; | ||
|
@@ -85,11 +143,13 @@ class FlamechartStackLayerView extends View { | |
surface: Surface, | ||
frame: Rect, | ||
stackLayer: FlamechartStackLayer, | ||
internalModuleSourceToRanges: InternalModuleSourceToRanges, | ||
duration: number, | ||
) { | ||
super(surface, frame); | ||
this._stackLayer = stackLayer; | ||
this._stackFrameSet = new Set(stackLayer); | ||
this._internalModuleSourceToRanges = internalModuleSourceToRanges; | ||
this._intrinsicSize = { | ||
width: duration, | ||
height: FLAMECHART_FRAME_HEIGHT, | ||
|
@@ -160,9 +220,19 @@ class FlamechartStackLayerView extends View { | |
} | ||
|
||
const showHoverHighlight = _hoveredStackFrame === _stackLayer[i]; | ||
context.fillStyle = showHoverHighlight | ||
? hoverColorForStackFrame(stackFrame) | ||
: defaultColorForStackFrame(stackFrame); | ||
|
||
let textFillStyle; | ||
if (isInternalModule(this._internalModuleSourceToRanges, stackFrame)) { | ||
context.fillStyle = showHoverHighlight | ||
? COLORS.INTERNAL_MODULE_FRAME_HOVER | ||
: COLORS.INTERNAL_MODULE_FRAME; | ||
textFillStyle = COLORS.INTERNAL_MODULE_FRAME_TEXT; | ||
} else { | ||
context.fillStyle = showHoverHighlight | ||
? hoverColorForStackFrame(stackFrame) | ||
: defaultColorForStackFrame(stackFrame); | ||
textFillStyle = COLORS.TEXT_COLOR; | ||
} | ||
|
||
const drawableRect = intersectionOfRects(nodeRect, visibleArea); | ||
context.fillRect( | ||
|
@@ -172,7 +242,9 @@ class FlamechartStackLayerView extends View { | |
drawableRect.size.height, | ||
); | ||
|
||
drawText(name, context, nodeRect, drawableRect); | ||
drawText(name, context, nodeRect, drawableRect, { | ||
fillStyle: textFillStyle, | ||
}); | ||
} | ||
|
||
// Render bottom border. | ||
|
@@ -264,13 +336,22 @@ export class FlamechartView extends View { | |
surface: Surface, | ||
frame: Rect, | ||
flamechart: Flamechart, | ||
internalModuleSourceToRanges: InternalModuleSourceToRanges, | ||
duration: number, | ||
) { | ||
super(surface, frame, layeredLayout); | ||
this.setDataAndUpdateSubviews(flamechart, duration); | ||
this.setDataAndUpdateSubviews( | ||
flamechart, | ||
internalModuleSourceToRanges, | ||
duration, | ||
); | ||
} | ||
|
||
setDataAndUpdateSubviews(flamechart: Flamechart, duration: number) { | ||
setDataAndUpdateSubviews( | ||
flamechart: Flamechart, | ||
internalModuleSourceToRanges: InternalModuleSourceToRanges, | ||
duration: number, | ||
) { | ||
const {surface, frame, _onHover, _hoveredStackFrame} = this; | ||
|
||
// Clear existing rows on data update | ||
|
@@ -285,6 +366,7 @@ export class FlamechartView extends View { | |
surface, | ||
frame, | ||
stackLayer, | ||
internalModuleSourceToRanges, | ||
duration, | ||
); | ||
this._verticalStackView.addSubview(rowView); | ||
|
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
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
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.
any particular reason to move these?
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.
So they can be accessed by the
isInternalModule
check also.