Skip to content

Added performance timings to DevTools named hooks parsing #22173

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

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Aug 25, 2021

This can be turned on or off (statically) via a new __PERFORMANCE_PROFILE__ flag in react-devtools-shared/src/constants. For now, it's disabled, but it's useful to turn on when performance profiling.

When enabled, the flag will generate measures like:

Screen Shot 2021-08-25 at 10 57 31 AM

Screen Shot 2021-08-25 at 10 59 50 AM

@bvaughn bvaughn requested review from jstejada and lunaruan August 25, 2021 18:22
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Aug 25, 2021

let potentialReactHookASTNode = null;
if (originalSourceColumnNumber === 0) {
// This most likely indicates a source map type like 'cheap-module-source-map'
// that intentionally drops column numbers for compilation speed in DEV builds.
// In this case, we can assume there's probably only one hook per line (true in most cases)
// and just fail if we find more than one match.
const matchingNodes = hooksFromAST.filter(node => {
const matchingNodes = hooksFromAST.filter((node, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is index being used anywhere here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. It was initially (when I added some logs) and I just forgot to remove it. Will do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we have a lint rule for unused declarations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, generally, but I guess it doesn't apply to function params.

@@ -152,12 +169,13 @@ export function getHookName(
potentialReactHookASTNode = matchingNodes[0];
}
} else {
potentialReactHookASTNode = hooksFromAST.find(node => {
potentialReactHookASTNode = hooksFromAST.find((node, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here

This can be turned on or off (statically) via a new __PERFORMANCE_PROFILE__ flag in react-devtools-shared/src/constants. For now, it's disabled, but it's useful to turn on when performance profiling.
@bvaughn bvaughn force-pushed the devtools-named-hooks-performance-timing branch from 59ca485 to 84d013b Compare August 25, 2021 19:32
@bvaughn bvaughn merged commit 8456457 into facebook:main Aug 25, 2021
@bvaughn bvaughn deleted the devtools-named-hooks-performance-timing branch August 25, 2021 19:39
zhengjitf pushed a commit to zhengjitf/react that referenced this pull request Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants