webelo
webelo

Reputation: 1903

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.)

Upvotes: 21

Views: 2433

Answers (1)

user11349250
user11349250

Reputation: 191

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.

Upvotes: 19

Related Questions