Skip to content
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

prevent spamming warnings related to performance measurement code #7299

Merged
merged 4 commits into from
Jul 19, 2016
Merged

prevent spamming warnings related to performance measurement code #7299

merged 4 commits into from
Jul 19, 2016

Conversation

sassanh
Copy link
Contributor

@sassanh sassanh commented Jul 18, 2016

Preventing spamming warnings related to React performance measurement code: #6842

@ghost
Copy link

ghost commented Jul 18, 2016

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

@ghost ghost added the CLA Signed label Jul 18, 2016
@@ -52,6 +52,9 @@ var currentTimerStartTime = null;
var currentTimerNestedFlushDuration = null;
var currentTimerType = null;

var beginLifeCycleTimerHasWarned = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it’s fine to have a single variable for this. If it warns once, something’s messed up already so it might warn more times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wanted to be safe about it. Thought maybe tests can produce situations that both functions generate warnings and then check the output of both. Changed it as you suggested in new commit.

@gaearon gaearon self-assigned this Jul 18, 2016
@ghost ghost added the CLA Signed label Jul 18, 2016
@ghost
Copy link

ghost commented Jul 18, 2016

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

'There is an internal error in the React performance measurement code. ' +
'Did not expect %s timer to start while %s timer is still in ' +
'progress for %s instance.',
timerType,
currentTimerType || 'no',
(debugID === currentTimerDebugID) ? 'the same' : 'another'
);
lifeCycleTimerHasWarned = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This sets it regardless of whether the warning has occurred. Sorry I didn't realize this at first.

It seems like it would indeed be easier to add an if (currentTimetType) here. The warning would just get lifeCycleTimerHasWarned as an argument.

Same below.

Sorry I didn't see this at first!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Np happens, I'm glad you found it. Just fixed it in new commit.

currentTimerType || 'no',
(debugID === currentTimerDebugID) ? 'the same' : 'another'
);
lifeCycleTimerHasWarned = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

No, this is still incorrect.
Let me clarify: warning() doesn’t actually produce a warning unless its first argument is false.

This code is not a warning path by itself.

var isEverythingBad = false;
warning(!isEverythingBad, 'Everything is bad');

will not produce a warning. I know it’s a bit confusing but if you think of warning() as of something like assert(), it will make sense. The first argument is the condition you expect to be true.

In the current code, you set lifeCycleTimerHasWarned in any case, regardless of whether the warning was actually printed. So it gets silenced on the first check, not on the first warning.

This should work instead:

if (currentTimerType) {
  warning(
    lifeCycleTimerHasWarned,
    ...
  );
  lifeCycleTimerHasWarned = true;
}

Alternatively:

if (currentTimerType && !lifeCycleTimerHasWarned) {
  warning(
    false,
    ...
  );
  lifeCycleTimerHasWarned = true;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, fixed it in a new commit.

@gaearon
Copy link
Collaborator

gaearon commented Jul 19, 2016

This looks good to me. Have you had a chance to try this in a real project?

@sassanh
Copy link
Contributor Author

sassanh commented Jul 19, 2016

I tested it in my project and it only warns once.

@gaearon gaearon added this to the 15-next milestone Jul 19, 2016
@gaearon gaearon merged commit 1cc9a5d into facebook:master Jul 19, 2016
@gaearon
Copy link
Collaborator

gaearon commented Jul 19, 2016

Thanks!

@sassanh
Copy link
Contributor Author

sassanh commented Jul 19, 2016

Thank you!

@zpao zpao modified the milestones: 15.3.0-test, 15-next, 15.3.0 Jul 21, 2016
zpao pushed a commit that referenced this pull request Jul 22, 2016
)

* prevent spamming warnings related to performance measurement code

* minor changes in names and such

* -

* -

(cherry picked from commit 1cc9a5d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants