Firefox 4 Performance

Dave Mandelin from the JS team and Joe Drew from the Graphics team summarize the key performance improvements in Firefox 4.

The web wants fast browsers. Cutting-edge HTML5 web pages play games, mash up and share maps, sound, and videos, show spreadsheets and presentations, and edit photos. Only a high-performance browser can do that. What the web wants, it’s our job to make, and we’ve been working hard to make Firefox 4 fast.

Firefox 4 comes with performance improvements in almost every area. The most dramatic improvements are in JavaScript and graphics, which are critical for modern HTML5 apps and games. In the rest of this article, we’ll profile the key performance technologies and show how they make the web that much “more awesomer”.

Fast JavaScript: Uncaging the JägerMonkey
JavaScript is the programming language of the web, powering most of the dynamic content and behavior, so fast JavaScript is critical for rich apps and games. Firefox 4 gets fast JavaScript from a beast we call JägerMonkey. In techno-gobbledygook, JägerMonkey is a multi-architecture per-method JavaScript JIT compiler with 64-bit NaN-boxing, inline caching, and register allocation. Let’s break that down:

    Multi-architecture
    JägerMonkey has full support for x86, x64, and ARM processors, so we’re fast on both traditional computers and mobile devices. W00t!
    (Crunchy technical stuff ahead: if you don’t care how it works, skip the rest of the sections.)

    Per-method JavaScript JIT compilation

    The basic idea of JägerMonkey is to translate (compile) JavaScript to machine code, “just in time” (JIT). JIT-compiling JavaScript isn’t new: previous versions of Firefox feature the TraceMonkey JIT, which can generate very fast machine code. But some programs can’t be “jitted” by TraceMonkey. JägerMonkey has a simpler design that is able to compile everything in exchange for not doing quite as much optimization. But it’s still fast. And TraceMonkey is still there, to provide a turbo boost when it can.

    64-bit NaN-boxing
    That’s the technical name for the new 64-bit formats the JavaScript engine uses to represent program values. These formats are designed to help the JIT compilers and tuned for modern hardware. For example, think about floating-point numbers, which are 64 bits. With the old 32-bit value formats, floating-point calculations required the engine to allocate, read, write, and deallocate extra memory, all of which is slow, especially now that processors are much faster than memory. With the new 64-bit formats, no extra memory is required, and calculations are much faster. If you want to know more, see the technical article Mozilla’s new JavaScript value representation.
    Inline caching
    Property accesses, like o.p, are common in JavaScript. Without special help from the engine, they are complicated, and thus slow: first the engine has to search the object and its prototypes for the property, next find out where the value is stored, and only then read the value. The idea behind inline caching is: “What if we could skip all that other junk and just read the value?” Here’s how it works: The engine assigns every object a shape that describes its prototype and properties. At first, the JIT generates machine code for o.p that gets the property by laborious searching. But once that code runs, the JITs finds out what o‘s shape is and how to get the property. The JIT then generates specialized machine code that simply verifies that the shape is the same and gets the property. For the rest of the program, that o.p runs about as fast as possible. See the technical article PICing on JavaScript for fun and profit for much more about inline caching.

    Register allocation
    Code generated by basic JITs spends a lot of time reading and writing memory: for code like x+y, the machine code first reads x, then reads y, adds them, and then writes the result to temporary storage. With 64-bit values, that’s up to 6 memory accesses. A more advanced JIT, such as JägerMonkey, generates code that tries to hold most values in registers. JägerMonkey also does some related optimizations, like trying to avoid storing values at all when they are constant or just a copy of some other value.

Here’s what JägerMonkey does to our benchmark scores:

That’s more than 3x improvement on SunSpider and Kraken and more than 6x on V8!

Fast Graphics: GPU-powered browsing.
For Firefox 4, we sped up how Firefox draws and composites web pages using the Graphics Processing Unit (GPU) in most modern computers.

On Windows Vista and Windows 7, all web pages are hardware accelerated using Direct2D . This provides a great speedup for many complex web sites and demo pages.

On Windows and Mac, Firefox uses 3D frameworks (Direct3D or OpenGL) to accelerate the composition of web page elements. This same technique is also used to accelerate the display of HTML5 video .

Final take
Fast, hardware-accelerated graphics combined plus fast JavaScript means cutting-edge HTML5 games, demos, and apps run great in Firefox 4. You see it on some of the sites we enjoyed making fast. There’s plenty more to try in the Mozilla Labs Gaming entries and of course, be sure to check out the Web O’ Wonder.

About Stormy Peters

Stormy Peters is Director of Websites and Developer Engagement at Mozilla. She is passionate about open source software and educates companies and communities on how open source software is changing the software industry. She is a compelling speaker who engages her audiences during and after her presentations and frequently speaks on business aspects of open source software.

More articles by Stormy Peters…


33 comments

  1. timmywil

    Great job guys! It still has some catching up to do to match the speeds of webkit, but there is a lot of improvement. On the other hand, I have been seeing some impressive numbers where jager will outperform JavascriptCore by 2 times in certain use cases. For instance, http://jsperf.com/set-vs-function-call

    March 22nd, 2011 at 08:20

  2. Michael Butler

    Do you think Firefox 4 will one day get Hardware Acceleration on Linux installations?

    March 22nd, 2011 at 08:42

    1. David

      Je l’espère bien il faudrait savoir si Firefox vas plus vite sur la version 11.04 de Linux-Ubuntu.

      March 22nd, 2011 at 09:46

    2. Mélanie

      Yep, I’m happy with firefox 4, but I’ll be happier when HW acceleration is available on Linux.

      March 22nd, 2011 at 10:37

  3. Lars Gunther

    @Michael

    It has quite a few GPU accelerated features, through XRender. Unfortunenately Mozilla seems to forget to tell that in their marketing – for mo apparent reason.

    March 22nd, 2011 at 12:34

  4. Cezary Tomczyk

    Finally. We are waiting for the official version of Firefox 4th.

    March 22nd, 2011 at 12:37

  5. nemo

    timmywil, webkit doesn’t really have much to do with javascript. Do you mean v8 or jsc? In that case, on those fronts, Firefox 4 does quite well indeed. See arewefastyet.com for latest JSC and v8 vs various TM+JM (and a nice breakdown of the new work here.

    http://arewefastyet.com/?a=b&view=regress

    In my personal kraken tests:
    http://m8y.org/tmp/kraken.xhtml it seems that Firefox does quite well.

    As for rendering where you could legitimately say webkit I’d say Firefox 4 does even better.what you’re testing, but I wouldn’t call it barely

    March 22nd, 2011 at 16:23

  6. timmywil

    nemo: Good to see. I did mention JavascriptCore, but I actually wasn’t aware that webkit was not affiliated with a certain Javascript engine.

    March 22nd, 2011 at 18:33

  7. QOAL

    (The ‘making’ link in the last section is borked btw.)

    March 23rd, 2011 at 05:48

  8. Jens

    ACK. How will hw accel for Win and Mac help me on Linux?

    March 23rd, 2011 at 11:43

  9. nemo

    Jens, there’s a couple of points on that front.
    1) Firefox has had hardware acceleration for Linux through Xrender for a loooong time.
    2) Firefox has hardware acceleration for linux built in in addition to that for supported graphics cards, and you can try MOZ_GLX_IGNORE_BLACKLIST=1 environment variable if you think your card might work anyway.

    Personally, I have had no trouble with fglrx/ATI on all the ATI cards I’ve tried, so on those I’ve set that variable in my /etc/profiles.d system-wide.

    On Intel cards, I had trouble getting through:
    https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/tests/webgl-conformance-tests.html
    without crashing under Ubuntu 10.10 (Ubuntu 11.04 worked fine) so I didn’t set that by default, even though most stuff worked fine.

    March 23rd, 2011 at 13:36

  10. Jim Wrobel

    What is the explanation for the V8 part of the bar graph? It looks like FX4 is actually 6x slower than FX3.6.

    March 24th, 2011 at 06:29

  11. nemo

    Jim, v8bench doesn’t use a time in milliseconds, but rather a weighting score across all portions of the benchmark. Described in the v8bench FAQ I believe. Anyway, I don’t think due to the scoring that it is precisely 6x faster, the scoring is geometric or something.

    Anyway. Higher is better for v8bench.

    March 24th, 2011 at 13:57

  12. Dwight Stegall

    Someone above said FF4 has some catching up to do with Webkit. It’s easy to make a browser fast when there is nothing in it (Chrome & Safari). I’d rather have a slower browser like Firefox that allows you to tweak it internally and has addons second to none. Go ahead and use those worthless Webkit browsers. The rest of us will be laughing at you while we are dong tings you can’t. Google, for instance, restricts what extension developers can do. That’s why their extension are nearly useless.

    March 24th, 2011 at 22:41

  13. Dwight Stegall

    The one thing I dislike about Firefox is there is no easy way to change the color of the scrollbars. I’m not talking about changing them so everyone can see them. I just want to add CSS to userChrome.css so only I can see the changes. This way it bothers no one.

    March 24th, 2011 at 22:49

  14. Brett Zamir

    Firefox 4 is slow for me (on Vista). Even with all extensions disabled, doing things as simple as page up/page down gives unacceptable delays in responses. I’m seriously sticking with 3.6 now because of it which I thought would be solved by the final release, and unfortunately it is not. Hard to believe I am the only one, but this is very noticeable. Even if graphics or rendering is faster, it’s not much use if the UI is poorly responsive.

    March 27th, 2011 at 00:26

    1. tristian

      your not the only one I have the same issue…

      April 1st, 2011 at 18:03

  15. WW

    In Linux Fedora 14 I solved my slow javascript issues by disabling the default nouveau video driver and installing the nvidia drivers for my video card.

    March 27th, 2011 at 12:49

  16. naresh

    firefox is taking much memory in ubuntu linux.It is a bit slow as compared under windows.Hope firefox 4 will solve this issue!

    March 28th, 2011 at 10:22

  17. Richard

    page up/page down is a disaster on FF 4.0

    April 21st, 2011 at 01:55

    1. Brett Zamir

      Are you on Vista? That’s where I was having the awful page up/down problem too

      April 22nd, 2011 at 07:43

  18. Tony Cochran

    Firefox 4 is SLOW. and it’s killing me. It’s bad enough that it takes LONGER to load pages than IE or Firefox 3…. tab groups load like MOLASSES.

    April 24th, 2011 at 02:19

  19. Matthew

    Have no idea what you folks are talking about in terms of specs. But I went ahead and downloaded Firefox 4 last night when I saw the invite. Looks and feels like a completely different browser – and way quicker than the old one. I’m a happy camper.

    Tried Google Chrome twice – and got rid of it twice. Ran very slow on my computer. Internet Explorer seems to be necessary for a few rare websites – slowest of all. But maybe it’s the antique Dell Dimension 3000 computer that I use.

    May 1st, 2011 at 06:36

  20. Eesger Toering

    Hello,

    I have switched from Opera to Firefox since the first full version (1.0 2004) and I have always been very happy and impressed by this piece of software.

    Up and until I decided to upgrade to version 4, I even tried 4.0.1 but that version also is more then extremely slow (opening a new tab takes up to one minute, no exaggeration! I run Windows XP) After a some work I was able to downgrade to version 3.6.17… (plugins..)

    My experience with version 4 is more then dramatic, but I also get complaints of my personnel and from customers that “my hailed FireFox” isn’t what it used to be.

    Please get it all working again as smoothly as you once did!

    Best regards,

    E. Toering

    May 23rd, 2011 at 01:49

    1. louisremi

      Hi Eesger,
      As you can guess, not all users are experimenting similar problems, otherwise we wouldn’t have had 150M downloads in about 6 weeks ;-)
      That being said, I recommend you either search the Internet how to create a fresh new profile for Firefox and start from here.
      Regards,
      Louis-Rémi

      May 23rd, 2011 at 08:34

  21. Eesger Toering

    Hi Louis-Rémi,

    Thank you for replying! I think I will be rebuilding my computer anyway somewhere the next few weeks (when I find the time;-). And as said, something got really strange in my computer (probably Murphy, he tends to find me more then I like to). But what worries me is that the overall stability doesn’t seem to have improved (based upon several remarks I have heard over the last few months).

    I’m sorry I can’t be more specific.

    Best regards,

    E. Toering

    May 24th, 2011 at 16:16

  22. jerry

    so my pc is running windows 7. before i upgraded to firefox 4 the internet seems fast, can open many tabs without it slowing down, and the loadings were fast. once i went ff4 i notice the new look, but i also notice that it was slower compare to the previous firefox3. i was wondering if there is a way to fix this or if i should just go back to the old version? it seems that i might not be the only one with the ff4 problem.

    May 29th, 2011 at 16:02

    1. louisremi

      Hi Jerry,
      you can start by saving your bookmarks and passwords using Firefox Sync and then create a brand new profile using the profile manager.

      May 30th, 2011 at 02:55

  23. bray

    Pretty disappointed in FF4. If creating a new profile is necessary for even marginally acceptable performance, you should tell users that before we bother with downloading it. How many of those 150M downloads end up being people more than annoyed that you broke their browsing experience?

    June 10th, 2011 at 18:19

  24. Dave

    C’mon FF4 needs 512mB of RAM and 200mB of hard disc space to get going, now that ain’t a step forward in my book! The other builds require far less, right now I can’t think of any other browser that needs so much resource.

    Funny no one mentioned about the WebGL flaw…. this applies to FF4, Chrome, Safari and Opera, see this link http://www.theregister.co.uk/2011/05/11/chrome_firefox_security_threat/

    For the time being I’m staying with FF3.5 build. FF4 BTW seems to phone home 24/7 ‘a little more than usual’.

    June 14th, 2011 at 13:03

  25. John

    I like firefox 4. Much better than my previous version installed. The only thing I hate about this version is the compatibility issue with google page speed

    July 4th, 2011 at 08:05

  26. nmn

    It’s nice to see how in benchmarks firefox becomes faster and faster (in a couple of years probably we will need atomic clocks precision to measure it). Yet firefox becomes slower and slower on our computers. Looking forward for some more intelligent computers that will be able to understand the benchmark figures and run faster.

    August 23rd, 2011 at 03:07

  27. pgecet 2011

    The Plug ins for fire fox are very useful and innovative but they should be updated to all fire fox versions

    September 14th, 2011 at 11:42

Comments are closed for this article.