Slashdot Mirror


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."

36 of 297 comments (clear)

  1. Firefox is required anyway. by Tsingi · · Score: 5, Interesting

    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?

    1. Re:Firefox is required anyway. by stms · · Score: 5, Insightful

      I use firefox because my plugins make the web a much nicer place to be.

    2. Re:Firefox is required anyway. by bemymonkey · · Score: 3, Informative

      Agreed - and the power consumption is much lower than Chrome's (the only viable alternative, IMO) too.

      But how do I speed it up? Chrome is MUCH faster on my machine, and I'm using a Firefox profile that's barely a year old, without many add-ons installed (NoScript and ABP go without saying... ImageZoom, NoSquint... that's pretty much it). And Firefox keeps thrashing my disk (No, I'm not swapping it out for an SSD - I only have one hard drive slot in my laptop, and it's filled with a big-ass mechanical hard drive)...

    3. Re:Firefox is required anyway. by TheRaven64 · · Score: 4, Insightful

      I don't see your on-topic post. I see an article about software engineering techniques used to reduce memory consumption, with FireFox used as a case study. You then post about how FireFox protects your privacy. This is about as on-topic as a post saying that you use Android because you prefer the user interface in an article about a new feature in the Linux kernel improving battery life on ARM.

      --
      I am TheRaven on Soylent News
    4. Re:Firefox is required anyway. by Ihmhi · · Score: 4, Insightful

      Agreed. IE is shit, and I don't trust Chrome.

      I know it might be judged as paranoid and irrational (and to a degree, it is), but I really want the bare minimum of Google products on my computer. I just don't trust them. I've seen too many previously "good" companies abuse their power once their product is entrenched on everyone's computer, and I don't want to give Google much of a chance in that respect.

      Firefox isn't only the best for my needs, it's also the least of all evils that has the features I want.

  2. Re:misslabeled linke by bunratty · · Score: 2
    How do you figure that?

    Under a heavy load of 40 tabs, Safari for Windows uses the least amount of memory (just 725 MB). Firefox comes in second at 910 MB, followed closely by Opera at 925 and Chrome at 995. Microsoft's own IE9 uses the most memory (1.75 GB).

    --
    What a fool believes, he sees, no wise man has the power to reason away.
  3. Give us more options by Anonymous Coward · · Score: 5, Insightful

    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.

    1. Re:Give us more options by hedwards · · Score: 5, Interesting

      250ish MB or RAM is hardly unreasonable and is significantly better than the alternatives. If you don't like the RAM use with Firefox then you sure as hell aren't going to be happy with the competition. I haven't seen a benchmark or other comparison in a long time where Firefox didn't trounce the competition by a significant margin.

      TFA does raise an important point that the memory consumption problems are mostly with certain add ons. The vanilla install itself doesn't have those issues.

    2. Re:Give us more options by 0123456 · · Score: 2, Insightful

      No, it shouldn't use any more memory than it needs.

      How much memory does it need? I'd much rather that it cached recent pages in RAM than on disk or not at all.

      250MB is nothing on a modern PC with many gigabytes of RAM. My laptop has 6GB, and logged into Gnome with Firefox and another app running the OS is using a whole 900MB, only about half of which is being used by applications. Why not do something useful with the rest of the RAM?

    3. Re:Give us more options by jank1887 · · Score: 2

      Need. What does anyone need? here's the issue. no one cares a hoot how much memory a program needs until you need it for something else. Yes, minimum memory usage is bad when it means your program isn't doing as much as you'd want or like it to do. But, when you set the browser to use a ton of memory, and then need it for something else, how does the computer respond? Few programs can suddenly release a chunk of memory for you because some other program has requested more than is available. If it can, there is lag. Or, heaver forbid, disk swapping. Until memory management is speedy and seamless, there needs to be sufficient available ram for what you might want to do, or you'll be upset when there's a slowdown or hangup. That happy level depends more on the underlying OS than the program, but the program gets to decide how much it wants to try to grab.

      I agree with a previous poster, user comparability makes sense here. Most users would probably miss it, but those who don't could at least make the choice and only blame themselves, and not the program, if things get clunky.

    4. Re:Give us more options by Seumas · · Score: 5, Insightful

      I have a lot of RAM, too. And Firefox runs like shit. It has for years and I've constantly heard the response of "no, you don't understand! it's just how it handles its back button function! That's why it uses two or three gigabytes!". I have 16gb on my primary system, so it can certainly use a few gigs if it really wants to. The question is - does it need to? More importantly, how does it perform when it's using so much RAM? That is the real problem.

      For years, I have put up with the experience of Firefox slowly grinding to a crawl. Within hours (certainly within a day at the most), it reaches 2.5gb or more memory usage and becomes unusable. Almost every action - typing, scrolling, clicking a button, entering a URL, clicking a link - causes it to hang temporarily. Sometimes for almost a minute. Click a tab. Hang. Scroll to the bottom of the page. Hang. Type in the text box. Hang. Submit. Hang. Close tab. Hang. Terrible experience.

      And, I stuck with it. Restarting the browser every few hours just became part of the experience (starting around early 3x, I believe). I primarily stuck with it, because I love Firefox and have used it forever. And Mozilla before that. And Netscape before that. Part of that is that I cut my teeth as an engineer at Netscape when I was young. It was my first real job. So I had a particular affinity for it, always. Besides, eventually they'd fix the issues. Even though they went forever claiming there weren't any memory issues . . . until sometime recently (last year, I think?) when there finally seemed to be acknowledgement of it.

      Most of all, I like having the access to extensions. Primarily, adblocking extensions. And then the tree tabs extension. And then panorama/tab candy was built into 4x. I tried Chrome several times, but their shitty handling of many tabs was terrible. I couldn't tolerate it. Firefox did it beautifully.

      And then, I finally got fed up. After all those years and all the delaying and all the excuses I made for Firefox, I decided a couple months ago that I would go full time Chrome and just see what it was really like. The result? I'm sold on Chrome, now. I can't believe I'm saying this, but I am. I never have to restart due to it behaving slow. I never have to restart due to it using too many resources. I never have it beach-balling for a minute at a time for every action I do. I never have Windows telling me the application has stopped responding. It just works.

      And here's the thing. It uses just as many resources, sometimes. Just like Firefox, I sometimes find it using as much as 3gb of memory. But where Firefox would start grinding to a halt around 1.5-2.5gb of usage, Chrome just keeps smoothly chugging along under as much as 3gb (and possibly more, but it never has used more than that, so I don't know).

      So, we can make all the excuses we want for Firefox. When it comes down to it, what matters is that my browsing habits cause Firefox to perform fucking terribly, while Chrome doesn't flinch. And when it comes down to my time and sanity, I need performance; not excuses.

    5. Re:Give us more options by TheRaven64 · · Score: 5, Informative

      I want firefox to use up as much of it as it can to improve my browsing experience

      RTFA. When FireFox has an off-by-one error in its JavaScript string concatenation code that causes it to allocate twice as much memory as it needs for JavaScript strings, it's not using memory to improve your browsing experience, it's just using memory. When FireFox is storing decompressed images in memory that never actually make it to the screen, it's not using memory to improve your browsing experience, it's just using memory.

      Most of the techniques in TFA were of general interest to anyone working on a large project, not just to FireFox.

      --
      I am TheRaven on Soylent News
    6. Re:Give us more options by 93+Escort+Wagon · · Score: 3, Informative

      Listen up, young'un - I remember when we bought a 10MB hard disk for our lab's HP1000 mini-computer back in the early 1980s. That thing was the size of a dishwasher.

      --
      #DeleteChrome
    7. Re:Give us more options by iMadeGhostzilla · · Score: 2

      I wish each tab had a flag "this tab is important -- don't release memory allocated with this tab if not visited for a while." Most of my browser memory is wasted on tabs that I didn't bother to close even though I'm not coming back to them.

    8. Re:Give us more options by webheaded · · Score: 2

      I wish I could give you like a million mod points for this. I don't know if it's the memory usage or what, but Firefox just runs like shit all the time now. I had a Quad core (Q6600) and 4gb of RAM. There is no sane reason that Firefox should hang and run like shit all the time. I honestly don't care how much memory it uses but it's the fact that it runs like SHIT. You have the exact same experience I do: it hangs all the time. On everything. For no reason...like I'll open a new tab, start to type an address and it HANGS. I load up a website, tab freeze, entire browser becomes unresponsive and I just have to sit and twiddle my thumbs while it works it out.

      You even started using Chrome around the same time I did. The interface is like...lightyears ahead of Firefox. I too had previously tried Chrome and not really liked it much, but the slower and slower Firefox got, the more I really took a liking to Chrome. My favorite thing? A website is loaded up with every script on the Planet Earth (eg: Slashdot) and the tab starts to freeze. Solution? Click another tab and do something else while that issue sorts itself out. On Firefox? Sit and wait...hope the browser comes back and doesn't crash. This was one of the most jarring differences for me. The browser interface itself is ALWAYS usable. I can ALWAYS switch to another tab and I can ALWAYS get to the address bar and menus no matter what is happening. I don't know what is so different in Chrome that it is so much faster and usable in general...but Firefox needs to get with the program. I'm hoping that Firefox does what they say they were going to do and separate the browser process from the tabs. That one thing I think would improve Firefox performance across the board because it doesn't matter how fast your page loads are if the browser interface is constantly freezing and hanging.

      My one sore loss are the extensions. There are many alternatives but a lot aren't QUITE as good. The best example is ad block. It doesn't block video ads properly anymore like the Firefox version does. They've been improving a bit but at the moment it ONLY seems to block Youtube or if it does block somewhere else, it just breaks the video player. I am however happy to report that a vast majority of the extensions I used in Firefox are either ported to or have an equivalent in Chrome. The only thing I could not find a replacement for is DownThemAll...which sucks because I REALLY love that extension. :(

      --
      "Those who would sacrifice essential liberties for a little temporary safety deserve neither liberty nor safety." - BenF
    9. Re:Give us more options by gbjbaanb · · Score: 2

      I think the big deal here is that memory was wasted, and the guy has done his profiling and tooling and has reduce the wastage dramatically.

      Good job that man.

      However, in general, apps that use lots of ram are bad for you - you may have 8Gb, but if it uses all that, your whole system is going to be slower simply because all the data is being sloshed around inside your PC. The days where more ram = fast PC is gone, today your CPU cache is the new bottleneck that turns your screaming-fast 3ghz processor into a tapping-its-fingers 3ghz processor as it waits for the memory to be shuffled over the bus. Using more ram is often just sloppy programming anyway, which is why a lot of people take issue with it (and, of course, if you try to run 2 huge memory hogs at the same time....)

      Anyway, Firefox uses less memory, there's a great article explaining why and I'm happy.

    10. Re:Give us more options by forkazoo · · Score: 2

      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.

      I have 16 GB on my main system, and I don't want Firefox sucking up all my RAM. Firefox devs seem to miss a few key points about what I think is a very common usage model: A - Browsing is not my primary Application. (For me, it's graphics software. Other people may have MS Office or an IDE.) B - Browsing is the one app where I never want to lose state. (I'm willing to close my compositing app from time to time to free up resources for other things because it is my "Primary" action. I'm either doing it or I'm not. I can close it down between sessions and open the one document I was working on when I get back to it. The Browser should be "always there," because it has stuff like my gmail, and I want to see new mail come in. It also has dozens of tabs of unfinished reading because, again, browsing isn't my primary activity so whenever something comes up, I leave it quickly and come back to it in downtime.) C - I will have multiple browsers open at any given time. (On Windows, I may need IE for an intranet thing. For me, I usually have FF + Chrome so I can be signed into work and personal google accounts at the same time. So,w ahetever RAM is a reasonable allocation for browsing, Firefox should take less than a third of that.)

      So, even if browsing would be slightly improved by filling up tens of GB's of RAM with cached nonesense, I never actually want that to go to Firefox. I want Firefox to stay as conservative as possible so that I can comfortably leave my dozens of tabs open while I usu an app that's actually important, and then come back to them without losing the "mental state" of what I was reading on IMDB and wikipedia and my google searches about potions to make somebody fall in love with me, or whatever the hell I was doing.

    11. Re:Give us more options by schlachter · · Score: 2

      Damn it. I want my memory used! I didn't buy 16GB to have it just sit around inside my machine. What do I care about the details?! Bring it on Firefox!

      --
      My God can beat up your God. Just kidding...don't take offense. I know there's no God.
  4. Firefox's problem by TheLink · · Score: 5, Insightful

    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.

    --
    1. Re:Firefox's problem by hedwards · · Score: 3, Informative

      It depends which ones you're talking about. Some of them are already in their own separate process and you can kill those processes without having too much trouble. The bigger problem right now is all the freezing that goes on. I'm not sure what the problem is, but it gets a lot worse when I also have thunderbird open.

    2. Re:Firefox's problem by olau · · Score: 4, Informative

      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.

      Actually, the presentation addressed that. They're going to add a notice to known bad add-ons at the Mozilla add-on page (social engineering), and also add a basic leak test to things done by the reviewers.

  5. Re:misslabeled linke by Tsingi · · Score: 4, Informative

    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.

  6. Re:i'll do my own tests by Anonymous Coward · · Score: 5, Insightful

    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"?

  7. More configurable, better plugins. by guidryp · · Score: 4, Insightful

    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.

  8. Pale Moon browser by kriston · · Score: 4, Interesting

    Windows users should investigate the Pale Moon browser over at www.palemoon.org. Firefox optimized and without all the gunk.

    --

    Kriston

  9. In my experience... by Windwraith · · Score: 2, Funny

    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.

  10. Re:i'll do my own tests by Thud457 · · Score: 4, Funny

    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

  11. It isn't a memory leak... by nitehawk214 · · Score: 2

    ... 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
  12. Re:Slop analysis doesn't add up by jlebar · · Score: 3, Informative

    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.

  13. Memory leaks are easy by kbg · · Score: 3, Interesting

    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.

    1. Re:Memory leaks are easy by BZ · · Score: 4, Interesting

      You should read the article, which actually touches on this. One issue is that a "memory leak" can include memory that does in fact get released at shutdown, especially in garbage-collected systems (not a problem in C, of course).

      So you can have situations where you close a tab but its memory is kept alive for a while because an extension is referencing it. Not a leak in the C sense, but a leak in the sense the user cares about.

    2. Re:Memory leaks are easy by _0xd0ad · · Score: 2

      The problem is not finding where in the source malloc was called. That is easy. The problem is finding where free wasn't. That is harder.

  14. Re:Slop analysis doesn't add up by TheRaven64 · · Score: 2

    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
  15. A couple of problems by alexo · · Score: 2

    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.

    1. Re:A couple of problems by Korin43 · · Score: 3, Insightful

      Both machines run FF 3.6 because I keep reading that later versions have worse memory use and UI performance characteristics.

      ... people say that 3.6 is more responsive (especially on older HW) than the newer versions.

      Those people are wrong. Newer versions of Firefox are *much* faster and use less memory. In fact, lowering memory usage became a priority right about the time you stopped upgrading. Ironic, eh?

  16. Re:misslabeled linke by BZ · · Score: 2

    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.