question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Profiling javascript thread performance

See original GitHub issue

Description

When profiling a react-native app, often the bottleneck is in the JS thread. But there’s no way to know which javascript functions are the bottleneck.

As shown in the profiling doc, we can’t see the exact js calls:

image

Reproduction

I’ve reproduced it by using systrace.py as shown in the docs and got a profile looking like this:

image

Solution

Ideal solution would be some doc to use the V8 profiler.

Also, for react.js, we have React.addons.Perf. Maybe showing how to use it for react-native would be also nice.

EDIT3: looks like using react-addons-perf solve most of the issues for my specific case, I should maybe include it in the docs

I don’t know much about the react-native profiling infrastructure, maybe there’s already something built-in that I missed.

EDIT: after a bit more of research, I saw a few things:

EDIT2: also, looks like something is planned

image

I’m interested in contributing a PR for this if necessary.

Additional Information

  • React Native version: 0.30.0
  • Platform: android
  • Operating System: linux

EDIT4: managed to something like what I wanted with react-addons-perf by using something like this:

import Perf from 'react-addons-perf';

....
    componentDidMount() {
        console.log('start perf tracking');
        Perf.start();
        setTimeout(() => {
            console.log('stop perf tracking');
            Perf.stop();
            Perf.printExclusive();
        }, 10000);
   }
...

But something nicer would be to be able to get a flamegraph

EDIT5: Looks like debugging with chrome allow to use the profiler from chrome directly, making this whole issue solved

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
jeremyongcommented, Dec 12, 2016

With react-addons-perf and Perf.start/Perf.stop I wasn’t able to measure anything (getLastMeasurements always returns an empty array). What might I be doing wrong?

2reactions
jeremyongcommented, Dec 12, 2016

Yep tried that too. I get zero output. When I tried debugging it, it seemed like the Perf module being imported wasn’t instrumenting the same component that react native was using. Also, I verified that the react, react-addons-perf, and react-dom versions matched my RN version. Note that the react-addons-perf module transitively imports the react-dom debug tool.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to profile javascript performance in google chrome?
Open the chrome browser with any website. · Hit F12 OR right click on the screen and select “inspect element” · In the...
Read more >
Profiling & Optimizing the runtime performance with the ... - TK
Investigating performance problems with the devtools performance tab and improving the web performance of the React runtime application.
Read more >
Mastering Chrome Developer Tools Profiling the Main Thread
Since JavaScript is single-threaded, it's important to be able to identify the process running on the main thread of the application.
Read more >
What is the best way to profile javascript execution? [closed]
At first I want to see profile stats of every javascript function and execution time. Next would be including DOM functions. This combined...
Read more >
Week 1: JavaScript Profiling Using Chrome Dev Tools
JavaScript Profiling shows us which function or processes take most of the time and runtime performance shows how Musicblocks performs when it's running....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found