tl;dr

Firefox 7 uses less memory than Firefox 6 (and 5 and 4): often 20% to 30% less, and sometimes as much as 50% less. In particular, Firefox 7’s memory usage will stay steady if you leave it running overnight, and it will free up more memory when you close many tabs.

This means that Firefox 7 is faster (sometimes drastically so) and less likely to crash, particularly if you have many websites open at once and/or keep Firefox running for a long time between restarts.

Background

Firefox has a reputation for being a memory hog, and the efficiency with which it uses memory has varied over the years. For example, Firefox 2 was quite bad, but Firefox 3, 3.5 and 3.6 were substantially better. But Firefox 4 regressed again, partly due to a large number of new features (not all of which were maximally efficient in their first iteration), and partly due to some over-aggressive tuning of heuristics relating to JavaScript garbage collection and image decoding.

As a result, Mozilla engineers started an effort called MemShrink, the aim of which is to improve Firefox’s speed and stability by reducing its memory usage. A great deal of progress has been made in only 7 weeks, and thanks to Firefox’s new rapid release cycle, each improvement made will make its way into a final release in only 12–18 weeks. (These improvements are available earlier to users on the Aurora and Beta channels.) Firefox 7 is the first release to benefit from MemShrink’s successes, and the benefits are significant.

Quantifying the improvements

Measuring memory usage is difficult: there are no standard benchmarks, there are several different metrics you can use, and memory usage varies enormously depending on what the browser is doing. Someone who usually has only a handful of tabs open will have an entirely different experience from someone who usually has hundreds of tabs open. (This latter case is not uncommon, by the way, even though the idea of anyone having that many tabs open triggers astonishment and disbelief in many people. E.g. see the comment threads here and here.)

Endurance tests

Dave Hunt and others have been using the MozMill add-on to perform “endurance tests“, where they open and close large numbers of websites and track memory usage in great detail. Dave recently performed an endurance test comparison of development versions of Firefox 6, 7, and 8, repeatedly opening and closing pages from 100 widely used websites in 30 tabs. The following graphs show the average and peak “resident” memory usage for each browser version over five runs of the tests. (“Resident” memory usage is the amount of physical RAM that is being used by Firefox, and is thus arguably the best measure of real machine resources being used.)

Obviously the measurements varied significantly between runs. If we do a pair-wise comparison of runs, we see the following relative reductions in memory usage:

Minimum resident: 1.1% — 23.5% (median 6.6%)

Maximum resident: -3.5% — 17.9% (median 9.6%)

Average resident: 4.4% — 27.3% (median 20.0%)

The following two graphs showing how memory usage varied over time during Run 1 for each version. Firefox 6’s graph is first, Firefox 7’s graph is second. (Note: Compare only to the purple “resident” lines; the meaning of the green “explicit” line changed between the versions and so the two green lines cannot be sensibly compared.)

Firefox 7 is clearly much better; its graph is both lower and has less variation.

MemBench

Gregor Wagner has a memory stress test called MemBench. It opens 150 websites in succession, one per tab, with a 1.5 second gap between each site. The sites are mostly drawn from Alexa’s Top sites list. I ran this test on 64-bit builds of Firefox 6 and 7 on my Ubuntu Linux machine, which has 16GB of RAM. Each time, I let the stress test complete and then opened about:memory to get measurements for the peak resident usage. Then I hit the “Minimize memory usage” button in about:memory several times until the numbers stabilized again, and then re-measured the resident usage. (Hitting this button is not something normal users do, but it’s useful for testing purposes because causes Firefox to immediately free up memory that would be eventually freed when garbage collection runs.)

For Firefox 6, the peak resident usage was 2,028 MB and the final resident usage was 669 MB. For Firefox 7, the peak usage was 1,851 MB (a 8.7% reduction) and the final usage was 321 MB (a 52.0% reduction). This latter number clearly shows that fragmentation is a much smaller problem in Firefox 7.

(On a related note, Gregor recently measured cutting-edge development versions of Firefox and Google Chrome on MemBench. The results may be surprising to many people.)

Bookmarks

Nathan Kirsch from Legit Reviews performed a simple test comparing Firefox 5 against Firefox 7. He clicked “Open all in Tabs” on a bookmark bolder containing 117 bookmarks — causing each bookmark to be opened in a separate tab. Once they all finished loading, he used the Windows Task Manager to measure the “private working set” (which is not that same as “resident”, but will correlate strongly with it). Firefox 7 used half a GB less memory than Firefox 5 — a 39.7% reduction.

Conclusion

Obviously, these tests are synthetic and do not match exactly how users actually use Firefox. (Improved benchmarking is one thing we’re working on as part of MemShrink, but we’ve got a long way to go. ) Nonetheless, the basic operations (opening and closing web pages in tabs) are the same, and we expect the improvements in real usage will mirror improvements in the tests.

This means that users should see Firefox 7 using less memory than earlier versions — often 20% to 30% less, and sometimes as much as 50% less — though the improvements will depend on the exact workload. Indeed, we have had lots of feedback from early users that Firefox 7 feels faster, is more responsive, has fewer pauses, and is generally more pleasant to use than Firefox 4, 5 and 6.

The reduced memory usage should also result in fewer crashes and aborts on Windows, where Firefox is built as a 32-bit application and so is typically restricted to only 2GB of virtual memory.

Mozilla’s MemShrink efforts are continuing. The endurance test results above show that development versions of Firefox 8 already have even better memory usage, and I expect we’ll continue to make further improvements as time goes on. We also have plans to improve our testing infrastructure which should help prevent future regressions in memory usage.