Making Firefox Feel as Fast as its Benchmarks – Part 1 – Towards Async

October 8, 2013 § 17 Comments

Most of us have seen the numbers: according to benchmarks, Firefox is faster than Chrome. Sadly, that is sometimes hard to believe, as our eyes often indicate the opposite. The good news is that Firefox really is very, very fast. However, this is misleading: what our eyes notice is not speed (an indication of how much time an operation takes to complete) but smoothness (an indication of how often we have refreshed the screen in the meantime). And on that domain, on many pages, we are still lagging behind Chrome.

In this series of blog entries about the subject,  I plan to introduce the issues and discuss the solutions that are envisioned.

How browsers work

Let’s start by a short refresher about how browsers work. All current browser engines (except Servo) share the same overall behavior:

function browser() {
  while (true) {
    handleEvents(); // <-- Your code goes here

Function handleEvents() handles all the system-specific event handling (“oh, it looks like the mouse has moved”, “some time has passed”, “the http request is complete”) and dispatches this to all higher-level code designed to provide the user experience (“call onmousemove“, “add something to the history menu”, “capture thumbnail”, “call XMLHttpRequest callback”, …). Whether you are writing back-end code, front-end code, an add-on or even web-side JavaScript, unless you are part of the Layout team, chances are that your C++ or JavaScript code is executed somewhere in handleEvents() and your CSS is executed in updateDisplay().

To ensure perfect smoothness, updateDisplay() must be called at least 30 times per second, preferably 60. This means that the whole loop should be executed in roughly 15ms, which is pretty short. This is a problem that hits all browsers and we have a number of techniques to fit our code in this limit. As I am not a member of the Layout team, I will concentrate on the code that runs in handleEvents().

So, we need to make handleEvents() faster. Can we optimize it? Certainly we can. However, recall that benchmarks suggest that Firefox is already the fastest browser around, and this is not sufficient. Perhaps we can improve that speed by a few percents, but that is not the best course of action.

We need to go the other way: handleEvents() must do less things.

In the following parts of this series, I will explore several options: going multi-process, multi-thread, or interruptible. If I have time, I will also discuss Servo, Mozilla’s next-generation rendering engine.


§ 17 Responses to Making Firefox Feel as Fast as its Benchmarks – Part 1 – Towards Async

  • Watcher says:

    Still waiting on the following bugs to be fixed:
    71668, 76495, 91351, 100951, 341046, 384323, 527728, 572459, 595574, 598873, 675866, 698547, 698919, 712478, 718121, 822096

    There’s no shortage of identifying the problems, just a shortage of fixes.

    • yoric says:

      I’m not sure what’s your point here.

      • Manoj Mehta says:

        I think what @Watcher was trying to say is that a number of problems have been identified. A new set of problems could exist as well, but it might help to fix the relevant problems already found and filed in bugzilla.

      • yoric says:

        I am not claiming to introduce any new problem or solution.
        What I’m trying to do is a form of performance tutorial for people who are not familiar with the Mozilla platform and how we are setting out to improve the responsiveness of Firefox – and, in a few cases, how they can contribute.

      • Watcher says:

        Look at it as another kind of benchmark, that will score you out of 16 on how many of these bugs get resolved either directly or indirectly as a result of you “setting out to improve the responsiveness of Firefox” with this series.

        At any time people can click my name to see how you’re doing.

      • yoric says:

        Well, it’s rather orthogonal to this series, but if you feel that it’s a good benchmark, sure.

    • J. McNair says:

      I think you’re missing the point. I’m fairly certain Mr. Teller is aware of most (or all) of those bugs. Anybody can post bug numbers, but those numbers don’t help people who want to understand why those bugs exist in the first place.

      I will guess that this and future posts will tell us more about how Firefox works and why it still has performance problems, despite all the improvements over the past 3 years. Perhaps we’ll find out what the remaining solutions are, which ones are best, and which ones will be implemented. Introductions and explanations are much nicer than diving into thousands of lines of code and dozens of bug reports with no guidance.

      I’m looking forward to this series, because I want to learn something.

  • Px says:

    So, bug 894128 got another chance? )

  • Jonathan J says:

    I too am looking forward to this series, this is a topic I find particularly interesting.

    I would definitely like to read more about Servo’s design and goals (and how they differ from traditional rendering engines.)

  • Stuart Axon says:

    This should be a good series, I always like reading a good post on optimisation, whether it’s performance, memory or perception 🙂

  • Nawfel says:

    Servo! Servo! Servo!

  • minidou says:

    what happened to part2?

    and why was it protected? 😦

  • […] didn’t scale up to today’s needs in terms of performance and performance perception, so we set out to rewrite the code and make it asynchronous wherever it matters. These days, many things in Firefox are asynchronous. Many services get started concurrently during […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

What’s this?

You are currently reading Making Firefox Feel as Fast as its Benchmarks – Part 1 – Towards Async at Il y a du thé renversé au bord de la table.


%d bloggers like this: