-
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 all commits
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
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
16 changes: 16 additions & 0 deletions
16
...-devtools-scheduling-profiler/src/content-views/utils/__tests__/__modules__/module-one.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,16 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export const outerErrorA = new Error(); | ||
|
||
export const moduleStartError = new Error(); | ||
export const innerError = new Error(); | ||
export const moduleStopError = new Error(); | ||
|
||
export const outerErrorB = new Error(); |
18 changes: 18 additions & 0 deletions
18
...-devtools-scheduling-profiler/src/content-views/utils/__tests__/__modules__/module-two.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,18 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export const moduleAStartError = new Error(); | ||
export const innerErrorA = new Error(); | ||
export const moduleAStopError = new Error(); | ||
|
||
export const outerError = new Error(); | ||
|
||
export const moduleBStartError = new Error(); | ||
export const innerErrorB = new Error(); | ||
export const moduleBStopError = new Error(); |
79 changes: 79 additions & 0 deletions
79
...eact-devtools-scheduling-profiler/src/content-views/utils/__tests__/moduleFilters-test.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,79 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its 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 {isInternalModule} from '../moduleFilters'; | ||
|
||
describe('isInternalModule', () => { | ||
let map; | ||
|
||
function createFlamechartStackFrame(scriptUrl, locationLine, locationColumn) { | ||
return { | ||
name: 'test', | ||
timestamp: 0, | ||
duration: 1, | ||
scriptUrl, | ||
locationLine, | ||
locationColumn, | ||
}; | ||
} | ||
|
||
function createStackFrame(fileName, lineNumber, columnNumber) { | ||
return { | ||
columnNumber: columnNumber, | ||
lineNumber: lineNumber, | ||
fileName: fileName, | ||
functionName: 'test', | ||
source: ` at test (${fileName}:${lineNumber}:${columnNumber})`, | ||
}; | ||
} | ||
|
||
beforeEach(() => { | ||
map = new Map(); | ||
map.set('foo', [ | ||
[createStackFrame('foo', 10, 0), createStackFrame('foo', 15, 100)], | ||
]); | ||
map.set('bar', [ | ||
[createStackFrame('bar', 10, 0), createStackFrame('bar', 15, 100)], | ||
[createStackFrame('bar', 20, 0), createStackFrame('bar', 25, 100)], | ||
]); | ||
}); | ||
|
||
it('should properly identify stack frames within the provided module ranges', () => { | ||
expect( | ||
isInternalModule(map, createFlamechartStackFrame('foo', 10, 0)), | ||
).toBe(true); | ||
expect( | ||
isInternalModule(map, createFlamechartStackFrame('foo', 12, 35)), | ||
).toBe(true); | ||
expect( | ||
isInternalModule(map, createFlamechartStackFrame('foo', 15, 100)), | ||
).toBe(true); | ||
expect( | ||
isInternalModule(map, createFlamechartStackFrame('bar', 12, 0)), | ||
).toBe(true); | ||
expect( | ||
isInternalModule(map, createFlamechartStackFrame('bar', 22, 125)), | ||
).toBe(true); | ||
}); | ||
|
||
it('should properly identify stack frames outside of the provided module ranges', () => { | ||
expect(isInternalModule(map, createFlamechartStackFrame('foo', 9, 0))).toBe( | ||
false, | ||
); | ||
expect( | ||
isInternalModule(map, createFlamechartStackFrame('foo', 15, 101)), | ||
).toBe(false); | ||
expect( | ||
isInternalModule(map, createFlamechartStackFrame('bar', 17, 0)), | ||
).toBe(false); | ||
expect( | ||
isInternalModule(map, createFlamechartStackFrame('baz', 12, 0)), | ||
).toBe(false); | ||
}); | ||
}); | ||
jstejada marked this conversation as resolved.
Show resolved
Hide resolved
|
69 changes: 69 additions & 0 deletions
69
packages/react-devtools-scheduling-profiler/src/content-views/utils/moduleFilters.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,69 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its 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 { | ||
FlamechartStackFrame, | ||
InternalModuleSourceToRanges, | ||
} from '../../types'; | ||
|
||
import { | ||
CHROME_WEBSTORE_EXTENSION_ID, | ||
INTERNAL_EXTENSION_ID, | ||
LOCAL_EXTENSION_ID, | ||
} from 'react-devtools-shared/src/constants'; | ||
|
||
export function isInternalModule( | ||
internalModuleSourceToRanges: InternalModuleSourceToRanges, | ||
flamechartStackFrame: FlamechartStackFrame, | ||
): boolean { | ||
const {locationColumn, locationLine, scriptUrl} = flamechartStackFrame; | ||
|
||
if (scriptUrl == null || locationColumn == null || locationLine == null) { | ||
// This could indicate a browser-internal API like performance.mark(). | ||
return false; | ||
jstejada marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// 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) || | ||
jstejada marked this conversation as resolved.
Show resolved
Hide resolved
|
||
scriptUrl.includes(INTERNAL_EXTENSION_ID) || | ||
scriptUrl.includes(LOCAL_EXTENSION_ID) | ||
// Unfortunately this won't get everything, like relatively loaded chunks or Web Worker files. | ||
) { | ||
return true; | ||
} | ||
|
||
// Filter out React internal packages. | ||
const ranges = internalModuleSourceToRanges.get(scriptUrl); | ||
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) { | ||
jstejada marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} |
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.