Performance Monitoring

Firefox Performance Monitoring

Fork me on GitHub
Highway velocity monitor

Troubleshooting

  • Problem Sometimes, Firefox sucks.
  • Solution Er..., we'll improve Firefox!

Troubleshooting

  • Problem Sometimes, my Firefox sucks.
  • Solution Oh, then it's probably an add-on!
  • Problem Er... which one?

How do we fix this?

  1. What is running?
  2. How slow is it?
  3. Report it!

So what's running?

The JS Stack

1 resource://gre/modules/Browser.jsm tabbrowser.prototype.openTab()
2 http://innocent.looking.blog.com/index.html letsPutAFacebookButton()
3 http://scripts.facebook.com/spam.js weShouldTrackThisUser()
4 http://scripts.facebook.com/spam.js letsLoadMegaresources()
5 chrome://adblockplus/resources/blocker.js isThisSpam()
6 chrome://adblockplus/resources/blocker.js wellWhatDoYouThink()
7 C++ code whoKnowsWhatHappensHere(Lchar[];1)
8 chrome://ghostery/resources/metoo.js heyGuysIKnowIKnow()
...
15 chrome://adblockplus/resources/blocker.js ahRightNowIKnowWhatToDoWithIt()
...

The JS Stack: Compartments

1 resource://gre/modules/Browser.jsm
2 http://innocent.looking.blog.com/index.html
3 http://scripts.facebook.com/spam.js
4 http://scripts.facebook.com/spam.js
5 chrome://adblockplus/resources/blocker.js
6 chrome://adblockplus/resources/blocker.js
7 C++ code
8 chrome://ghostery/resources/metoo.js
...
15 chrome://adblockplus/resources/blocker.js
...

The JS Stack: Owners

1 Firefox built-in code
2 http://innocent.looking.blog.com/index.html
3 http://scripts.facebook.com/spam.js
4 http://scripts.facebook.com/spam.js
5 AdBlock Plus
6 AdBlock Plus
...
8 Ghostery
...
15 AdBlock Plus
...

The story so far

  1. What is running?
  2. How slow is it?
  3. Report it!

So, how slow is it?

Measuring durations

1 Firefox built-in code
2 http://innocent.looking.blog.com/index.html
3 http://scripts.facebook.com/spam.js
4 http://scripts.facebook.com/spam.js
5 AdBlock Plus
6 AdBlock Plus
7 ...
8 Ghostery
...
15 AdBlock Plus
... ...

Measuring with a clock

Pros

  • Simple to implement.
  • Real-time data.

Cons

  • OS Clocks are slow.
  • OS Clocks... stop and jump and time travel?

Measuring with a profiler

setInterval(() => {
  while (true) {
    for (let frame of
getStack()) {
      
stats[frame.id] += 1 /* ms */;
    }
  }
}, 1 /* ms */);

+ postprocessing

Measuring with a profiler

Pros

  • Predictable/bounded CPU cost.
  • It works!

Cons

  • Interesting thread-safety issues.
  • Post-processing.
  • Unpredictable Battery costs.

Measuring with RDTSC

ReaD Time Stamp Clock: return the number of clock cycles elapsed on this core since the last reset.

Pros

  • It's very, very fast.

Cons

  • It's not synchronized between CPUs.

Measuring with RDTSC

1 Firefox built-in code
2 http://innocent.looking.blog.com/index.html
3 http://scripts.facebook.com/spam.js
4 http://scripts.facebook.com/spam.js
5 AdBlock Plus
6 AdBlock Plus
7 ...
8 Ghostery
...
15 AdBlock Plus
... ...
+ postprocessing

Measuring with RDTSC

Pros

  • No observable CPU cost.
  • No observable Battery cost.
  • Bounded errors.

Cons

  • Results are only reliable on average.

The story so far

  1. What is running?
  2. How slow is it?
  3. Report it!

But...

Bug 1210770 "addon might slow down browser" is inaccurate and annoying
Bug 1191342 Slow add-on warning, even if my add-ons do nothing
Bug 1188507 Nightly should not warn about Lightbeam making it run slowly
Bug 1152950 AddonWatcher should not inform the user at the first infraction
Bug 1200169 We should make the AddonWatcher more tolerant
Bug 1200172 Don't report slow add-ons if the system is hibernating
Bug 1219144 Only raise jank notifications if there is user-visible jank
... ...

It is slow but is it jank?

  • Am I in front of the screen?
  • Is something happening on-screen?
  • Am I expecting something to happen on-screen?
  • ...in this process?

Fixed, mostly

Bug 1210770 "addon might slow down browser" is inaccurate and annoying
Bug 1191342 Slow add-on warning, even if my add-ons do nothing
Bug 1188507 Nightly should not warn about Lightbeam making it run slowly
Bug 1152950 AddonWatcher should not inform the user at the first infraction
Bug 1200169 We should make the AddonWatcher more tolerant
Bug 1200172 Don't report slow add-ons if the system is hibernating
Bug 1219144 Only raise jank notifications if there is user-visible jank
... ...

The story so far

  1. What is running?
  2. How slow is it?
  3. Report it!

So, let's report it!

Telemetry

Towards self-support

Your Favorite Add-on is slow. Click here to will stop this annoying popup from showing.
Your Firefox seems to be running slowly. The good news is that Firefox has ideas to fix itself. Do you wish to try?
If only we had a task monitor... like about:performance.

Thanks

Red panda (Firefox)
  • David Rajchenbach-Teller
  • Tech Lead, Performance Team
  • @ImYoric
  • Slides: http://yoric.github.io/Fosdem-2016/html5/
Photo by Yortw