Closed Bug 1221503 Opened 9 years ago Closed 8 years ago

Firefox is slow (Windows swapping all the time)

Categories

(Firefox :: General, defect)

42 Branch
defect
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: e_gold, Unassigned)

Details

(Whiteboard: [bugday-20151109][MemShrink])

Attachments

(4 files)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0
Build ID: 20151029151421

Steps to reproduce:

Just working, openning pages, several tabs ~20


Actual results:

With time Firefox eats up A LOT of memory (>0.5GB on my old WinXP system with 1GB RAM, >1GB on this 640bit Win7). Windows starts swapping all the time, ALL geeeetts slllooowww. 


Expected results:

Firefox keeps working fast and also leave memory for other applications. At the moment Firefox (just to browse the web) is the leader in terms of consuming memory on my system. It consumes even more than photoshop.
reset your profile: https://support.mozilla.org/en-US/kb/reset-firefox-to-fix-most-problems

Anyway 1 GB on Win XP is too low to run the OS and applications, now recent applications use more memory than 10 years ago. And the web is heavy today.
That's exactly what my post is about. Modern applications by some (!) reason, use huge amount of memory and work worse than 10 years ago.

Actually the reason(s) are quite clear to me: 
1. bad programming style (not taking care about memory)
2. ambitions (programmers insert their own features that nobody needs)
3. bad understanding what the user really wants (new=modern interfaces, etc)

Another issue is WHY firefox updates on my WinXP if memory is not enough for the new version. Please, fix this. I spend now more time waiting for firefox that I would spend recovering from any security hole.
The web in 2015 is not the web in 2005, now, some webpages can load tens MB of memory, like Facebook.
About the memory use, Firefox did some huge improvements a few years ago, see the Memshrink project on BMO. Or about the JS engine (GCC eg).

Firefox is available on Win XP, you should be happy because many modern browsers don't support this EOLed OS anymore.

Anyway resetting the profile can help, then you need to configure the browser to reduce the memory footprint like disabling plugins by default, limiting the image decoding, blocking ads, etc.
Loic, you are basically telling me that on the other side of the web there are bad guys (e.g. facebook developers) who do not care about my browser's memory and create crazy pages. This I believe. (BTW, I stopped using facebook, but only because of poor and complicated interface.) Now comes my question, can I limit the amount of memory that firefox uses to render the page? I don't wanna give to any page more than 100kB. ;-)

Here, of course, comes the question: is it a lot or a little. From my point of view, 100kB is a lot, but it all depends how optimal are data structures (all this DOM, etc) that Firefox uses. I am sure they are not optimal.

I do not know details about "Memshrink project on BMO", but I did notices that after 500MB Firefox makes a lot of disk activity. In Task Manager, I see that memory consumption tries to grow but then Firefox shrinks something and it goes back. This, however, has limited effect. I have to restart firefox at least ones or twice a day (and them memory footprint is lower for the same opened tabs).

I will try resetting browser at home (WinXP). However, ad blocker actually consumes another 100MB. But I wanna have it.
Ed, did you had the chance to reset your profile as suggested in Comment 1? 
Did that improved your browsing experience?
Flags: needinfo?(e_gold)
Yes, profile was reset. At first it looked faster (no swapping), occupying ~350MB of RAM instead of typical ~500MB. A drawback: all plugins (With all settings :-( ) were gone. After re-installing some most urgent plugins (AdBlock+, Classic theme) I can confirm slight performance improvement (just my feeling) and RAM at 450MB instead of 500 (seen in Task Manager).

Note, at home I am still using outdated 30+ version of Firefox (and have forbidden updates) just to save my RAM.
Flags: needinfo?(e_gold)
¡Hola Ed!

Please provide a memory report as an attachment to this bug, see https://developer.mozilla.org/en-US/docs/Mozilla/Performance/about:memory

¡Gracias!
Alex
Component: Untriaged → General
Flags: needinfo?(e_gold)
Whiteboard: [bugday-20151109]
Attached file memory-report.json.gz
Memory report (several tabs open, Task Managers says Firefox occupies 620MB of RAM)
Flags: needinfo?(e_gold)
This morning I have studied the memory report myself and would like to tell the following. 

1. In my opinion 23MB for each sub-page of www.urlaubspiraten.de is a way too much. At the end the page is not that complex. I am sure that Firefox can optimize the storage of data structures here.

2. Of course, the guys at www.urlaubspiraten.de can be guilty too, supplying a huge page in terms of data or data structures (but not in terms of content). It is even larger than (more complex) vk.com - a Russian social network with much smaller footprint of ~13MB. This actually brings me to conclusion that Firefox should do something against the web sites with large appetite for memory. At the end this IS a security risk. Imagine that a web site send huge and complex HTML-page (or even generates on-the-fly some endless and complex HTML code on the server side) and Firefox tries to allocate 1,2,3,4 GB of memory...Windows never says "No", it says "Virtual memory low. Increasing the virtual memory size".....at the end the system dies in endless swapping. Aka DOS attack.

Proposal 1: optimize data storage.

Proposal 2: allow to set the memory limit (e.g. 1MB or 10MB) that Firefox allocates per page/window. 

Speaking more generally, I dislike the story with endless virtual memory and endless swapping. When there is no memory Windows should say "no memory". When JavaScript requests more memory from Firefox, Firefox should say no more memory. And applications should handle this gracefully rather hoping that there is memory always. This will also teach developers to save memory and be prepared for "no memory" case (error/exception handling etc).
Whiteboard: [bugday-20151109] → [bugday-20151109][MemShrink]
Judging by the memory report it looks like a fair amount of memory is being used by style-sets.

For example:
> │  │   │  │  ├───3.60 MB (00.59%) -- window(https://www.facebook.com/v2.4/plugins/page.php?adapt_container_width=false&app_id=425138760862879&channel=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter%2FwjDNIDNrTQG.js%3Fversion%3D41%23cb%3Df11e82a119de478%26domain%3Dwww.urlaubspiraten.de%26origin%3Dhttp%253A%252F%252Fwww.urlaubspiraten.de%252Ff11c77f5b0b2f2%26relation%3Dparent.parent&container_width=248&height=230&hide_cover=false&hide_cta=true&href=https%3A%2F%2Fwww.facebook.com%2FUrlaubspiraten&locale=de_DE&sdk=joey&show_facepile=true&show_posts=false&width=248)
> │  │   │  │  │   ├──2.51 MB (00.41%) -- layout
> │  │   │  │  │   │  ├──2.41 MB (00.40%) ── style-sets

In the past this has been caused by add-ons. Ed, can you try disabling your plugins to see if memory usage is reduced for the pages in your original report?
Flags: needinfo?(e_gold)
This is yet another memory report after Firefox was swapping like a crazy and then I closed all pages except 2 of google. To close it took time, but after coming to equilibrium I took this measurement. Guys, 435MB with only 2 pages open!!!
Flags: needinfo?(e_gold)
(In reply to Ed from comment #11)
> Created attachment 8687109 [details]
> Allpages closed except only 2 google pages (TaskManager says 435MB RAM
> occupied)
> 
> This is yet another memory report after Firefox was swapping like a crazy
> and then I closed all pages except 2 of google. To close it took time, but
> after coming to equilibrium I took this measurement. Guys, 435MB with only 2
> pages open!!!

Ed, thank you for the follow up. Can you try disabling your plugins to see if memory usage is reduced for the pages in your original report? This can be easily accomplished by starting in safe mode: https://support.mozilla.org/kb/troubleshoot-firefox-issues-using-safe-mode

This will help us determine if an add-on is causing your issues.
Flags: needinfo?(e_gold)
Here is memory report with addons disabled. TaskManager saus Firefox takes 449MB.
Firefox works kind of faster (almost no disk activity).

However urlaubspiraden.de window still takes around 18MB.
Flags: needinfo?(e_gold)
I noticed that you are using AdBlockPlus with an older version of Firefox. There was actually an issue fixed in Firefox 41 that improves memory usage with AdBlockPlus, so upgrading to the latest version may improve your memory usage.

You can see this blog post about it if you are interested:
https://blog.mozilla.org/nnethercote/2015/07/01/firefox-41-will-use-less-memory-when-running-adblock-plus/
Status: UNCONFIRMED → NEW
Ever confirmed: true
Andrew, thanks a lot! It's a very useful info.

However, you say that it MAY improve memory usage. And what should I do if it will become worse, e.g. because in parallel there comes a lot of other (unwanted) features? Is there (1 click) way back?

I think my main problem is that I do not believe to Firefox developers anymore.
(In reply to Ed from comment #15)
> However, you say that it MAY improve memory usage. And what should I do if
> it will become worse, e.g. because in parallel there comes a lot of other
> (unwanted) features? Is there (1 click) way back?

You could try installing Firefox Beta to try out a version that has the fix without overwriting your existing version. If you don't like it, you can uninstall Firefox. Though the version you are running is so old that running a profile with both may not work. But you could at least try out similar browsing and addons on a new profile.

Note that continuing to use an old version with known security exploits is a bad idea. For instance, Firefox 30 may be vulnerable to many exploits, including the one described in this blog post that was found on a website, and let malicious webpages read files from your hard drive:
https://blog.mozilla.org/security/2015/08/06/firefox-exploit-found-in-the-wild/

If you are unhappy with the UI of Firefox, you should look for addons that change the UI, or find a browser that has a UI that you like that is still receiving security fixes.

Anyways, sorry for this tangent. It sounds like your original reported issues are for a recent version of Firefox, so we should focus on that, because it may be something that we can address in a newer version.
Andrew, hi!

(In reply to Andrew McCreight [:mccr8] from comment #16)
> You could try installing Firefox Beta to try out a version that has the fix
> without overwriting your existing version. If you don't like it, you can
> uninstall Firefox. Though the version you are running is so old that running
> a profile with both may not work. But you could at least try out similar
> browsing and addons on a new profile.
 
> Note that continuing to use an old version with known security exploits is a
> bad idea. For instance, Firefox 30 may be vulnerable to many exploits,
> including the one described in this blog post that was found on a website,
> and let malicious webpages read files from your hard drive:
> https://blog.mozilla.org/security/2015/08/06/firefox-exploit-found-in-the-
> wild/

Let me tell you my view. (Automatic) updates is a good idea IN THEORY. However, in practice I decided against this. 

Updates not only fix bugs, but also add some new garbage-features nobody asked for. Examples: build-in PDF viewer, new GUI, tours, new options GUI. As a result Firefox becomes slow (occupies more memory causing swapping) or even requires to invest time from the user (wow, new interface that nobody asked for, but I am forced to learn just now when I came to my office and planned to do something urgent). Even worse, new features (like build-in PDF viewer that nobody asked for) bring new bugs (see your link) making the update loop infinite with new garbage-features with more new bugs inserted on every iteration. In this sense it absolutely does not matter, which version I have, with the old bugs or with the new ones. In this situation my choice is the old version because it has less features and was supposed to run fast on older PCs.

Let me give you my statistics:
1. The time I lost during the last 5 years because of security issues: 0
2. The time I spent fighting with new "features" (new GUI, something didn't work as before, writing bug reports here, just waiting because Firefox becomes slower with time): ~2 month total

I think the decision not to update anymore is obvious. And don't mention that software is free. It is not. It costs me huge amount of time (and therefore money) when updates are on. Therefore they are off. I wonder who is the guy who decides about all this unnecessary changes? I wanted to voluntere to "help" in making this decisions, but it seems that such help is not needed. ;-)






> 
> If you are unhappy with the UI of Firefox, you should look for addons that
> change the UI, or find a browser that has a UI that you like that is still
> receiving security fixes.
> 
> Anyways, sorry for this tangent. It sounds like your original reported
> issues are for a recent version of Firefox, so we should focus on that,
> because it may be something that we can address in a newer version.
oh, boy. yet another example mozilla reliability is the "Save changes" button here, which actually does "Send/Post message". :-( As far as I see I cannot edit my previous post above.
Andrew, I continue...

Your proposal like "try installing this and that..." basically translate into "invest more of your time" without any result guarantee. Sorry, I wanna spend my time in different way. I need the Firefox that simply works without any time investment from my side. At the moment the only version which satisfies this request is the old one, which still runs although slow and needs to be restarted every 2 hours. 

Concerning your request to report about the newest version. Yes, I have it running on other system with 4GB of RAM. The problems are basically the same. They only come a bit later when Firefox occupies about 1.7GB of RAM.

All in all, considering my total lost of confidence in any next version, I see only one exit from the current situation -- re-start Firefox project. Make a new Firefox light, free from all unneeded functions and features. Make it small and fast as Firefox was in the very beginning. All extra features, should be as plugins.

P.S. I am sorry about this global view (instead of discussing a particular bug), but it seems that the people who make global decisions about Firefox development do not really understand what they are doing. So, feel free to pass this text to them as I do not know who they are.
FWIW, the extension Classic Theme Restorer can restore pretty much everything in the GUI to the way it was before. It makes the GUI extremely configurable, so you can cherry-pick the changes you like.

I wouldn't worry about pdfjs (it's just JavaScript, it won't be used unless you're actually viewing a pdf), but if you hate it that much you can turn it off by setting pdfjs.disabled to true in about:config.

For the most part, newer versions of Firefox should be faster, not slower. We have many automated performance tests trying to ensure this. Newer versions of Firefox should also use *less* memory in many situations, not more, although base memory usage has gone up over time (but we're talking an increase on the order of 100MB, not gigabytes).

If you just want to unload unused tabs (1GB is *really* not a lot of memory for the web today, nothing Firefox can do about that), you could try this extension: https://addons.mozilla.org/en-us/firefox/addon/auto-unload-tab/

The reason this is not built into Firefox, other than because it adds yet another feature to maintain, is that we don't want users to lose state just because a tab is in the background - session restore doesn't save everything, because it would take up too much space. But if you can live with the possibility of losing some state because a webpage has to be reloaded, it might be a good option for you.
Emanuel, 

I am using classic theme restorer. Issue 1: I do not believe that implementation of new GUI+addon occupies less memory that GUI implemented within Windows and only called from Firefox (standard controls). Issue 2: the new tours got completely crazy with classic GUI addon and I had to spend time filing the bug here, just because somebody included tours and does not check return values ;-) you are right, why do we need to maintain this tours feature. Kill it! 

I do not know the details about your tests. My typical setup is 1GB of RAM with Windows XP and several applications (Acrobar, thunderbird, etc ) running and ca. 20 tabs with "modern" (=fat) pages like facebook open and eventually touched during few hours. As soon as Firefox occupies more than 500MB of RAM, it gets sloow swapping permanently. Do you have such tests with deficit of memory?  

1GB? I disagree totally - 1GB is A LOT of memory for a web page. If some guys are writing such crazy pages, I wanna tell them: you are trying DOS attack against me, your page does not render here, and you are not going to sell anything to me (those are mostly some crazy shops, etc). Period. Can I set this limit somehow? Because if you don't set limit such guys will occupy ALL your memory. For example, there is no guarantee that their JavaScript code does not have memory leakage.

You are completely right about maintaining new features. So, my proposal would be: kill tours, internal pdf viewer, new GUI, new options (I need more options like before with standard controls), pockets and other recent garbage. I will really appreciate it.
Yes, 1GB is a lot for a web page, but you just said you have 20 tabs open. 50MB per web page is really not that uncommon on the web today (especially with adblock plus inserting a lot of style rules into each page), even with Firefox trying its best to share as many structures as possible.

As for Firefox limiting its own memory usage, how do you envision that working exactly? Should it just stop loading pages? Start killing off background tabs? The extension I linked does something like that, but it's not something the session restore developers think Firefox should do by default on its own, since it risks losing data.

In any case, the direction of Firefox isn't up to me - I don't use Pocket myself either. I do know there's a project in the works that aims to split out some of the less used functionality into extensions, but I'm not sure which features they're thinking of splitting out.
I envision this as follows. I should have a setting in about:config, which says MaxMemPerPage=5MB or MaxMemPerWindow=10MB (I am not that familiar with internal working of Firefox). If the page exceeds this (HTML, DOM, images, JavaScript allocations), Firefox starts giving "no memory" to (the JavaScript of) this page. Careful programmer must check return values or process exceptions correctly ;-) Then we will immediately see who is who in web programming. If HTML/DOM does not fit, just show message "Page requires more memory than allowed per page in about:config MaxMemPerPage". OK.
oh, guys, wanna fresh example why automatic updates (in the way they exist) are bad? Here you go: https://bugzilla.mozilla.org/show_bug.cgi?id=1233683

At least my home PC (the one with version 32 :-)) is safe from bastards.
Okay, guys. I've got a bit of time due to xmas vacations and, following your suggestions, decided to install the latest Firefox 43.0.1 on my old home PC. I did it.

Some of you (Hello Emanuel) were claiming that new Firefox should do better with memory. THIS IS NOT TRUE, as I expected. New Firefox needs MORE memory and now almost systematically goes over 450MB. Which makes it slooow due to permanent swapping already at 5-7 open tabs. What does work better is memory consumption by AdBlockPlus. I do not see +-100MB jumps when I enable/disable it. In summary, those of you who claimed that Firefox 43 is faster than 32, feel free to send me 1GB memory chip or money (to buy it). No kidding.

Now I made new memory measurement. I worked as usual with Firefox, then closed ALL tabs and measured, see attachment. I am amazed that 100MB is taken by some js-non-window? I guess some JavaScript stuff, but why does it take 100MB? Then 91 MB is taken by heap-overhead??? huh? It seems I was right. Data structures are not optimal. In heap-overhead the biggest chunk is bin-unused. No comments ;-)Then 30MB is heap-unclassified. Also sounds like unneeded.
(In reply to Ed from comment #25)
> Some of you (Hello Emanuel) were claiming that new Firefox should do better
> with memory. THIS IS NOT TRUE, as I expected. New Firefox needs MORE memory
> and now almost systematically goes over 450MB.

It is true that the base memory usage of Firefox has gone up over time, as can be seen on https://areweslimyet.com, but the additional memory used by webpages and add-ons should be more under control, as your experiment with ABP seems to confirm. Unfortunately 450MB minus the 175MB for the process itself really isn't all that much for 5-7 webpages; we're talking 40-55MB per tab at that point.

> In heap-overhead the biggest chunk is bin-unused.

I guess this is from jemalloc, which allocates 4kB 'arenas' from 1MB 'chunks' to speed up allocation across threads. I'm guessing bin-unused is from chunks that are only partially in use but cannot be freed. Unfortunately this kind of heap fragmentation is pretty much insurmountable; you can't just defragment a heap because you'd have to update all the pointers into it. Firefox's GC can do this for JavaScript objects, but it doesn't work for C++ objects because they aren't garbage collected. On the plus side, jemalloc won't allocate any new chunks until the existing ones are exhausted, so bin-unused fragmentation is temporary.

> Then 30MB is heap-unclassified. Also sounds like unneeded.

heap-unclassified just tallies up all the tiny things we don't track. The aim is for this number to be 10% of the total heap or lower, since a high percentage indicates that we aren't tracking something that we should. But 30MB out of a 450MB heap sounds fine. Whatever objects make up heap-unclassified, they aren't unneeded, they're just individually small.

In any case, I don't really know what to tell you. 450MB is still less than half of your memory, so maybe there are other processes using a lot of memory. The only problem specific to Firefox here, as far as I can tell, is that its base memory usage has gone up - but there probably isn't anything easy we can do about that.
Emanuel, thanks for fast answer. However, I do not understand what is your suggestion now on improving the performance of my system. You made it worse ;-)

To everybody: I do believe that 40-50MB per web page is way too much. This surely is related to non-optimal data storage. Moreover, the main concern here is that any page resulting in 50MB of Firefox's memory represents a serious SECURITY RISK for a not so powerful system as my one and therefore should be stopped/interrupted/notrendered BEFORE the system will become unresponsive and dies. Firefox should clearly say that such a page represents a security risk for the health of the whole system. Only then developers will start doing something. The implementation of this mechanism I outlined in one of the posts above.

In summary, I believe the following measures are necessary:
1. stop rendering "fat" web pages (security risk)
2. optimize internal data structures to use less memory. 50 millions of bytes per web page is NOT okay
3. stop endless additions of features that increase base memory usage. Make such features optional. I do not need tours, pdf viewer, fancy GUI, etc...see above.
At this point I don't think there's anything actionable in this bug. Ed, please feel free to file follow ups for specific defects or enhancements you would like to see.

You may also find the following support sites helpful for determining how to disable features you find undesirable:
  - http://forums.mozillazine.org/
  - https://support.mozilla.org/en-US/

Additionally our Firefox newsgroup may be a useful resource for proposing new features and finding past discussions on the merits and shortfalls of features that have been added in the past:
  - https://groups.google.com/forum/#!forum/firefox-dev
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: