Why does Firefox cause high-CPU-usage "spikes" every few seconds?
Solution 1
I suspect it is either the Garbage Collector or the Cycle Collector.
In about:config
change javascript.options.mem.log
to true
. Now notices about GC and CC should be available in the Error console (Crtl+Shift+J) If their timing and duration matcher the freezing, then this is your problem.
When I had this problem I fixed it by blowing away my Firefox profile and creating a new one from scratch. The Firefox profiles have a tendency to gather a lot of crud over time.
Even this is not a prefect solution. If you open a lot of tabs in Firefox (100+) or lots of extensions and leave Firefox running for days on end it will inevitably slow down. You will need to restart Firefox every once in a while.
If you are like me and have a tendency gather a large collection of tabs you need get around to dealing with at some point another trick I use is to set browser.sessionstore.max_concurrent_tabs
to 0. This will stop Firefox from loading all the tabs of your session when starting. It will instead load them when you switch to them. I find this, plus the occasional restart of Firefox, greatly reduces the load of having a great many tabs.
Solution 2
In about:config
, set browser.sessionstore.interval
to a large number (it should be 10,000
or 15,000
; set it to about 600,000
).
Basically, this is the number of milliseconds between times that Firefox updates your "saved session". If you have many tabs open, or a long browsing history (or, as is often the case with me, both), this can be writing a ridiculous amount of data to the sessionstore.js
file every 10 or 15 seconds, which can cause Flash videos to freeze briefly or even render your entire computer frozen every few minutes.
Setting this value to a large number has the disadvantage that if Firefox crashes, you lose your last few minutes of browsing history when you try to restore. That's a small price to pay in my opinion.
Your CPU spikes should become much less frequent.
Solution 3
It won't fix memory leaks per se. But enabling "Don't load tabs until selected" will at least not load the tabs until you click on them after a restart, which keeps memory way down.
I also found using CCleaner to clean the Firefox "Session" helped a bit. Back up all your open tabs first as it removes the session recovery information. Before running CCleaner my sessionstore.js file was about 800 KB, but afterwards it's down to about 6 KB.
More information about sessionstore can be found in Solved: Firefox Freezes Every 10 Seconds, Scrolling is Jumpy.
Uninstalling Flashblock fixed my high CPU issues with Firefox. Perhaps Flashblock and Adblock Plus or some other extension don't get along?
Life's too short to mess around with Firefox. I just exported my bookmarks, and uninstalled Firefox, then deleted all the Firefox folders on the machine, and then reinstalled Firefox from scratch, and restored the bookmarks. Now it runs faster than Google Chrome with a totally new install.
Solution 4
It is very difficult to tell. Is it just general use that causes it, or are you accessing a specific site? (We had a problem where a browser gained memory over time because of a memory leak in jQuery).
Assuming you're using a Microsoft OS, you could try using Microsoft's Process Monitor tool. It spits out shed loads of messages, but you should be able to narrow them to the interval where the 'freeze' occurred, and maybe see what process is doing the blocking.
Related videos on Youtube
moritzebeling
Updated on September 18, 2022Comments
-
moritzebeling over 1 year
When I start Firefox, I have no problems for a while, but after a couple of days, CPU spikes start to occur. During a spike, Firefox freezes and then stops. Spikes occur every seven to ten seconds, and each spike lasts for two to three seconds. If I am typing when a spike occurs, characters output only after the spike. I initially thought this problem was because of Flash, so I disabled it, but the problem still occurs.
Also, Firefox's memory usage increases to over 600 MB after several days.
The list of Firefox plugins and extensions I use is available here.
-
John T about 13 yearsFirefox has always had memory leaks, that part is normal.
-
RomanSt over 12 yearsThe symptom is tracked in bug 490122. I don't seem to experience these in Firefox 4+ anymore - thankfully.
-
tvt173 over 11 yearsAnd every new version they promise they've fixed it! google.com.au/…
-
HikeMike over 11 years@MatthewLock What about this? It seems only users on Reddit feel like this gets addressed every version...
-
-
Rhys about 13 yearsjQuery can have a memory leak? Hrmmmmm
-
Rhys about 13 yearsSounds more like a browser issue and less of a jQuary issue is what I'm saying since it can't run but in a browser(well for most cases anyhow) :) (if while(1==1){} crashes a browser I blame the browser :P)
-
Mason Evans about 13 yearsWhile you are correct in asserting that the browser is at fault (some of the bugs on the above link were related to IE's failure to properly handle circular references), there are steps that a developer can take in their JS code to ameliorate these issues. In C/C++ you have to clean up memory you have manually allocated as there is no GC for you to do this. If you don't is this a fault in your code, or the runtime? I would argue that not accounting for the limitations of your environment can be considered a bug on your behalf, and it looks like that's exactly how the jQuery team view it too.
-
Rhys about 13 yearsWell this ended up in a silly argument :P. JavaScript is not code, it is script; script runs within another program. A poorly written program runs on it's own it requires proper writing because of this. A good program that accepts script will prevent it from breaking itself. Hence why if you check bugzilla, you'll see what are considered bugs relating to poorly written JavaScript causing Firefox to crash. This topic is pretty opinionated though, so I'll leave it at that! (The first comment was more of a joke since the browser leaks not jQuery)
-
Mason Evans about 13 years@Jeff F - Technology is so impersonal - :-) apologies if my tone seemed argumental - my intention was far from that. I did indeed take your original comment as you intended as was enjoying discussing. It's a little off topic though, so I'm happy to delete the above if you decide you want to.
-
moritzebeling about 13 yearsThere is Firefox plugin called BarTab. I assume it does same thing about browser.sessionstore.max_concurrent_tabs
-
Mr Alpha about 13 yearsYes, although I believe it is not updated for Firefox 4.
-
Rhys about 13 yearsna, it's all perspective :P
-
moritzebeling about 13 yearsI always upgraded and problem stayed. I prefer to live with Firefox 3.6.17
-
RomanSt over 12 years
-
Peter Mortensen almost 9 years"max_concurrent_tabs" does not appear to be in Firefox 40 (2015-08).
-
Peter Mortensen almost 9 yearsIn Firefox 40, it appears to save it in file "\sessionstore-backups\recovery.js" (note: in sub folder "sessionstore-backups") instead of "sessionstore.js" (and the previous version in "\sessionstore-backups\recovery.js").
-
Peter Mortensen almost 9 yearsOK, this seems to have changed with Firefox 33 (2014-06), not Firefox 40.
-
miyalys over 8 yearsI think the current equivalent of max_concurrent_tabs is the setting in preferences under "General" called "Don't load tabs until selected".
-
Hashim Aziz almost 7 yearsWow, a reasonably sane and civil argument on the internet. Definitely from 2011.