2018-02-17 18:59:29 +11:00
Some notes on the "Timing" tab in `re-frame-trace` .
2018-01-20 16:50:59 +11:00
2018-02-17 18:59:29 +11:00
## Be Sceptical Of The Numbers
2018-01-20 16:50:59 +11:00
2018-02-17 18:59:29 +11:00
Two reasons:
2018-01-20 16:50:59 +11:00
1. Accurately timing something in the browser is almost
a fool's errand. One moment it takes 1ms and the next it
2018-01-20 17:00:40 +11:00
takes 10ms, and you’ ll never know why. Noisy.
2018-01-20 16:50:59 +11:00
2018-02-17 18:59:29 +11:00
So, don't ever base decisions on one set of timings.
2018-02-17 20:22:35 +11:00
Click the "replay" button ([#115 ](https://github.com/Day8/re-frame-trace/issues/155 )) a few times to see if you
2018-02-17 18:54:43 +11:00
get stable numbers.
2018-01-20 16:50:59 +11:00
2018-02-17 18:54:43 +11:00
2. Don't freak out about any apparent slowness just yet.
2018-01-20 16:50:59 +11:00
2018-01-20 17:11:10 +11:00
After all, you're running a dev build, right, not the
production build? And I'm guessing you're also
running a dev build of React?
2018-01-20 16:50:59 +11:00
2018-01-20 17:11:10 +11:00
And using `re-frame-trace` will slow things
2018-01-20 16:50:59 +11:00
down too, what with all that creating and analysing of trace.
2018-01-20 20:20:36 +11:00
So, run the production version of your app first, before
deciding you have a performance problem. Something what
2018-01-20 16:50:59 +11:00
takes 100ms in dev might take 20ms in prod.
2018-01-20 20:20:36 +11:00
The Timing Tab is not really about absolute numbers so
2018-01-20 17:11:10 +11:00
much as the relative time taken to do the different
2018-01-20 20:20:36 +11:00
"parts" of an Epoch. Is one View very slow for some
2018-01-20 17:11:10 +11:00
reason, compared to others?
And, even then, remember point 1 (above).
2018-01-20 16:50:59 +11:00
2018-02-17 18:59:29 +11:00
## Know Your Epoch Timeline
2018-01-20 16:50:59 +11:00
2018-01-20 21:21:14 +11:00
The Timing Tab is easier to understand once you have internalised the
following graphic which shows how, operationally, the six dominoes play out,
over time, within the browser.
2018-01-20 16:50:59 +11:00
< img src = "https://raw.githubusercontent.com/Day8/re-frame/master/images/epoch.png" >
2018-02-17 18:59:29 +11:00
## Other Tips
2018-01-20 20:20:36 +11:00
You should probably have [React DevTools ](https://github.com/facebook/react-devtools )
installed because it is useful. But, it can also add drag and noise to timing results,
2018-01-21 10:54:13 +11:00
so disable it when trying to get more accurate timing figures.
2018-01-20 20:20:36 +11:00
Here is (React 16) advice on [debugging React performance with Chrome Devtools ](https://building.calibreapp.com/debugging-react-performance-with-react-16-and-chrome-devtools-c90698a522ad )
2018-01-22 14:13:04 +13:00
The [re-frame.core/debug ](https://github.com/Day8/re-frame/blob/master/src/re_frame/std_interceptors.cljc ) middleware is relatively slow, and runs interleaved with your application's events being processed. re-frame-trace gives you the same information in the app-db panel, but saves the calculations until after your application has finished running, so you don't get the performance cost included in your timing.