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

Show React events in the timeline when ReactPerf is active #7549

Merged
merged 2 commits into from
Aug 24, 2016
Merged

Show React events in the timeline when ReactPerf is active #7549

merged 2 commits into from
Aug 24, 2016

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Aug 23, 2016

This was released in React 15.4.0. Read the blog post.


When you open the page with ?react_perf (or manually call ReactPerf.start()), this emits console.time()ings which are interpreted specially by Chrome (and maybe other browsers, I haven’t checked).

Seems like a nice way to visualize what is being mounted / updated / unmounted.

It looks like this in Chrome Timeline:

screen shot 2016-08-23 at 21 42 17

Yay or nay?

},
onUpdateComponent(debugID) {
checkDebugID(debugID);
emitEvent('onUpdateComponent', debugID);
if (isProfiling && hasAdvancedConsoleFeatures) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These actually should be before emitEvent for better precision..

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@vjeux
Copy link
Contributor

vjeux commented Aug 23, 2016

This is awesome, we've had the same view on React Native with systrace and it's been really helpful to track down what was going on during render.

@vjeux
Copy link
Contributor

vjeux commented Aug 23, 2016

Outside of the label uniqueness issue and the missing check, sounds good to me :)

@ghost ghost added the CLA Signed label Aug 23, 2016
@jakepusateri
Copy link

I think performance.measure should be able to produce that same view without logging to the console: https://twitter.com/igrigorik/status/690636030727159808

This currently only seems to work on Chrome.
@gaearon gaearon changed the title Show console.time() when ReactPerf is started Show React events in the timeline when ReactPerf is active Aug 24, 2016
@ghost ghost added the CLA Signed label Aug 24, 2016
@gaearon
Copy link
Collaborator Author

gaearon commented Aug 24, 2016

I tried using performance.measure() but it has an annoying issue: if events are too close, it appears to swallow some events, and they may never “finish”:

screen shot 2016-08-24 at 16 58 12

This looks like a Chrome bug to me:

screen shot 2016-08-24 at 16 56 04

@gaearon
Copy link
Collaborator Author

gaearon commented Aug 24, 2016

OK, I found a workaround for Chrome issue.
Ready for a second review.

@@ -244,11 +301,13 @@ var ReactDebugTool = {
onBeginLifeCycleTimer(debugID, timerType) {
checkDebugID(debugID);
emitEvent('onBeginLifeCycleTimer', debugID, timerType);
markBegin(debugID, timerType);
Copy link
Contributor

Choose a reason for hiding this comment

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

So good, I was going to ask if you could make this less verbose and repetitive :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I wrote this PR yesterday while waiting for the taxi so it wasn’t really clean 😄

@vjeux
Copy link
Contributor

vjeux commented Aug 24, 2016

Yay, this is going to help so many people!

@gaearon gaearon added this to the 15-next milestone Aug 24, 2016
@gaearon gaearon merged commit 0a248ee into facebook:master Aug 24, 2016
@gaearon gaearon deleted the perf-timers branch August 24, 2016 17:40
@shaneosullivan
Copy link
Contributor

Is performance.measure() ideally the right way to do this? If so, can we follow up with the Chrome dev team to resolve the bug?

@vjeux
Copy link
Contributor

vjeux commented Aug 24, 2016

@shaneosullivan a bug was created and involved parties on Chrome team have cc-ed themselves https://bugs.chromium.org/p/chromium/issues/detail?id=640652

@paulirish
Copy link

paulirish commented Aug 25, 2016

We have a fix landing now for the Chrome bug: https://codereview.chromium.org/2276743004
Should be in tomorrow's Canary.


Update: Fix landed.


Update (sept 8th): Just FWIW, I benchmarked the cost of performance.mark() yesterday to understand what sort of overheard it has: https://gist.github.com/paulirish/2fad3834e2617fb199bc12e17058dde4
TL;DR: it's all good.

@zpao zpao modified the milestones: 15-next, 15.4.0 Oct 4, 2016
zpao pushed a commit that referenced this pull request Oct 4, 2016
* Show React events in the timeline when ReactPerf is active

This currently only seems to work on Chrome.

* Address Chrome issue

(cherry picked from commit 0a248ee)
@pavlelekic
Copy link

This is amazing, is there a way to run this for React Native for iOS?

@gaearon
Copy link
Collaborator Author

gaearon commented Dec 5, 2016

@pavlelekic I think it might just work when you use Chrome debugger? You'd need to import Perf addon from RN itself though, maybe require('react-native/lib/ReactPerf) would work. I’m not actually sure how people import it there.

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.

8 participants