Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Profiler: What do the timings mean?

I am using react profiler to make my app more efficient. It will commonly spit out a graph like this:

enter image description here

I am confused because the timings do not add up. For example, it would make sense if the total commit time for "Shell" was 0.3ms then "Main" was "0.2ms of 0.3ms." But that is not the case.

What precisely do these timings mean and how do they add up?

(note: I have read "Introducing the React Profiler" but it appears from this section that this time-reporting convention is new since that article.)

like image 718
webelo Avatar asked Nov 16 '18 17:11

webelo


People also ask

How do you use Profiler in React?

The profiler takes two props one is an id which is a String and another one is onRender which is a callback function. The call back function also takes a number of arguments: id(String): It shows the id that we have given to the profiler while rendering a component, it is unique and helps us track the component.

Is React fast or slow?

React is slow. I mean, any medium-size React application is slow. But before you start looking for alternatives, you should know that any medium-size Angular of Ember application is slow, too. And the good news is: If you care about performance, it's fairly easy to make any React application super fast.

Why are React apps slow?

Analytics tracking libraries, excessive CSS animations, non-optimized images, iframes, and many more factors can contribute to poor performance. You can use the Chrome DevTools Performance tab to debug these issues.


1 Answers

The first number (0.2ms) is the self duration and the second number (0.3ms) is the actual duration. Mostly the self duration is the actual duration minus the time spent on the children. I have noticed that the numbers don't always add up perfectly, which I would guess is either a rounding artifact or because some time is spent on hidden work. For example, in your case, the Shell has an actual time of 3.1ms and a self duration of 0.3ms, which means the 2 children (Navbar and Main), should add up to 3.1ms - 0.3ms, or 2.8ms. However, we see that the Navbar is not re-rendered, so it's 0ms, but the actual duration for Main is only 2.7ms, not 2.8ms. It's not going to have any impact in practical terms when you're performance tuning, but it does violate expectations a bit.

like image 89
user11349250 Avatar answered Sep 21 '22 08:09

user11349250