Notes On Reducing Firefox's Memory Consumption
Skuto writes "At yesterdays linux.conf.au Browser miniconference in Ballarat, Australia, Mozilla engineer Nicholas Nethercote gave a detailed presentation about the history of Firefox's memory consumption. The 37 slides-with-notes explain in gritty detail what caused Firefox 4's memory usage to be higher than expected, how many leaks and accidental memory use bugs were tracked down with Valgrind plugins, as well as the pitfalls of common memory allocation strategies. Current work is now focused on reducing the memory usage of popular add-ons such as AdBlock, GreaseMonkey and Firebug. Required reading for people working on large software projects, or those who missed that Firefox is now one of the most memory-efficient browsers in heavy usage."
I use other browsers for development, but only Firefox to browse, it's the only browser that I feel is actively protecting my privacy.
Any other opinions on that?
What a fool believes, he sees, no wise man has the power to reason away.
I have 8gb of memory on my main computer. I want firefox to use up as much of it as it can to improve my browsing experience. On my netbook, I have 1, I want it to sip as little as it can. There should be an easy way to tell the browser how much memory I want used for certain tasks such as caching and whatnot. Addons should have their own seperate allocation, and each individual addon should be configurable for how much memory it can use.
Free / Open source software is about choices to run things how you want to. With that said, I don't have much room to complain because I've never contributed code to FF.
My main point though, is that screaming "THE RAM USAGE IS TOO HIGH" is not effective. I have a lot of ram, and I want it to be used, just not wasted; and I want more control over it.
In my experience Firefox (minus plugins etc) has leaked/used less memory than Google Chrome.
BUT, when a plugin/page starts leaking lots of memory the difference is with Google Chrome you can close the offending tab/window and the memory is freed up. You don't lose your sessions, don't lose your place on other tabs/windows. You can even reopen the page (esp if the page just slowly uses more and more memory).
In contrast with Firefox you often have to close the entire browser to free up the memory. And IMO that's Firefox's biggest problem when it comes to memory.
It doesn't matter how much better Firefox is on its own at memory management, in practice many people using Firefox are using it because of the plugins (otherwise they'd be using some other browser), and the plugin developers may not be so good at memory management.
The final link actually shows Firefox is one of the most memory inefficient browsers in heavy usage.
That depends on how you look at it. With one tab open it is comparatively poor, but with 40 tabs open it's very good.
I don't particularly think FFX has even close to the best performance, but those metrics are good. What's more important, good management with a low footprint or a high one? I have to disagree with you there.
Yeah, most of the improvements were in the last 4-6 months.
Anyone else get tired of this... "blah blah, my favourite open source browser wasn't competitive with the commercial product by an ad agency that records every keystroke I type in the URL bar a long time ago, possibly due to some addons I was running, so I just completely gave up on it and whenever a story comes up on how it has improved, I just state how it sucked at some time in the past and I'll never try it again"?
I use FF because it is much more configurable (about:config has entries for more than any other browser), it also has more plug ins, and those plug ins it does have tend to be more effective for just about everything.
I also don't like Google Chrome calling home all the time (uninstalled). I also have IE9 and Opera installed.
Speed issues are moot outside of benchmarks these days (unless you are running IE7 on a netbook). IMO it is pure placebo effect to say one browser is faster than another in regular browsing on a modern computer.
Windows users should investigate the Pale Moon browser over at www.palemoon.org. Firefox optimized and without all the gunk.
Kriston
Firefox is the app that uses the most RAM in my system, has always been, even more that Skyrim under WINE. I tried Chrome for a while, and while I didn't dislike it, I simply didn't want to forfeit my customized environment.
However, I never saw Chrome as using any less RAM. I usually got Firefox with 20+ tabs open (and around 100 in "not loaded in RAM" mode with the new features, think old BarTab) grouped in Panorama groups. In Chrome, because tab space is small, I usually had around 20, and both browsers were consuming 400mb of RAM each. I'd say Firefox uses LESS memory overall.
Thing is, firefox FEELS slow. Try to open Youtube's subscriptions page and you'll lose control of the browser for at least one second.
I can easily see people unable to close their porn when their significant other enters the room. Porn moves the world, thus people would prefer to use Chrome for porn. Thus Chrome's usage rises while Firefox's decreases. If Mozilla makes it more convenient to use Firefox for porn, the browser usage will crush Chrome.
with over 340 open tabs
I think it's time for PybusJ to admit he has a pr0n problem...
the preceding comment is my own and in no way reflects the opinion of the Joint Chiefs of Staff
... its just accidental memory usage.
Oh good, I was starting to get worried there.
I'm a good cook. I'm a fantastic eater. - Steven Brust
See page 27 of the PDF. He explains that the allocator, jemalloc, rounds up some allocation requests to easier to handle size. He calls this wastage "slop". Then look at the final point on that page - in order to reduce slop, always allocate a power of two sized block, as those never have slop.
So in order to stop the allocator wasting memory by using up more memory than requested, we're supposed to ask for more memory than we need?
What's to stop us from changing a 1025-byte allocation to 1024 bytes, rather than 2048 bytes, as you assume? There's no reason we need round up, and indeed we usually don't.
But note that even when we do round up, it's still an improvement: The slop is rarely usable memory -- you can't use it without first calling malloc_usable_size to realize that you have any slop. But if we round 1025 up to 2048 bytes, now we have almost double the amount of memory to play with. We pay 2048 bytes either way, but when we round up, we get to use all the memory we allocated.
I have never understood why memory leaks are so problematic to find. When I was programming in C long ago and had memory leaks, I simply created my own wrappers for malloc and free that stored where in the source code it was being called from, then at the end of the program I could simply check this list and it would display all the memory that had not been released and the corresponding line in the source where malloc was called.
No, you're supposed to allocate and use a power of two. If you have a 34 bytes structure and a 20 bytes structure that are usually used together, then allocating them separately will waste 42 bytes of memory. Allocating them together will waste 10 bytes. Allocate a lot of them and this 30-byte-per-structure saving is a lot.
This is even more true for buffers. The example he gave was for a JavaScript string. This allocates a buffer that the string can grow into. If a string is any length between 512 and 1023 characters then it should be allocating a 1024 byte buffer for it, but instead was allocating a 2048 byte buffer, and when it got to 1024 bytes it was freeing this and allocating a 4096 byte buffer for it.
I am TheRaven on Soylent News
At work I have a quad core Q6700 with 4GB of RAM. At home I use an older single core Athlon 64 3500+ with 2GB of RAM. Both machines run Windows XP.
Both machines run FF 3.6 because I keep reading that later versions have worse memory use and UI performance characteristics.
On both machines, I experience two problems with FF memory usage (all figures were reported as "private bytes" by Sysinternals process explorer):
1) Memory usage keeps growing until it reaches a threshold (1.5GB on my home machine) after which FF locks hard with close to 100% CPU use and never recovers. Closing tabs did not bring the memory usage down in a perceptible way.
This used to require daily restarts of FF but lately the problem does not seem to happen that often. A restart can still cut the memory use by half (same tabs courtesy of session restore), which helps with problem #2 below, but it takes much longer to go over 1GB.
2) Periodic "stuttering" where FF will pause for a short period every once in a while with CPU usage spikes approaching 100%. The duration of the pauses seem directly related to the amount of memory that FF uses. That, and the periodic nature of the "hiccups", lead me to believe it is related to garbage collection.
Unfortunately, it makes viewing videos when FF is running (even using an external viewer) impractical, so I have to close FF and start IE8 each time I go to youtube,
There's a bug report that was opened almost 3 years ago (and still unassigned).
The responses that I get are:
* You're using an old version.
True, but according to the comments, bug 490122 is still present in the newer versions (up to v10) and people say that 3.6 is more responsive (especially on older HW) than the newer versions.
* It's the plugins/addons/extensions.
Perhaps, but the reason I use FF at all is because of the extensions and I would expect such an "extension-centric" product to help me figure out which one is misbehaving (for example, by reporting the memory usage of each tab).
Now, reading the article and the slides, I am getting hopeful that these issues are being addressed.
For Firefox and Safari, part of the difference is that they're 64-bit applications on Mac and 32-bit applications on Windows.
For Chrome and Opera, that's not an issue, since they're 32-bit both places.
Past that, Windows and Mac use different font and graphics subsystems. That's a pretty large chunk of memory usage right there that'll be very different. There might also be differences in allocations in various other system libraries.
Further, "the same memory allocations" can lead to very different results when different allocators are used. See http://pavlovdotnet.wordpress.com/2007/12/06/more-allocator-data-tcmalloc-edition/ and http://pavlovdotnet.wordpress.com/2007/12/04/vlad-and-analysis-of-dtrace-was-used/ for some data from a few years ago using different allocators for Firefox on Windows. At least for the Firefox version tested there the allocators are different on Windows and Mac: the Mac version uses the system allocator while the Windows version uses jemalloc. Newer versions use jemalloc on Mac as well.
I agree the result is interesting though, and having an idea of how much of it is attributable to which factor would be good. An apples-to-apples (so to say) comparison using a recent Firefox nightly with jemalloc on both Windows and Mac, running in 32-bit mode on Mac, might be interesting.