Why does Firefox cause high-CPU-usage "spikes" every few seconds?

9

3

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.

Boris_yo

Posted 2011-05-27T13:13:01.647

Reputation: 5 238

6Firefox has always had memory leaks, that part is normal. – John T – 2011-05-27T15:42:47.403

The symptom is tracked in bug 490122. I don't seem to experience these in Firefox 4+ anymore - thankfully.

– RomanSt – 2011-09-25T16:38:49.003

1

@MatthewLock What about this? It seems only users on Reddit feel like this gets addressed every version...

– Daniel Beck – 2013-01-13T11:54:45.217

Answers

8

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.

Mr Alpha

Posted 2011-05-27T13:13:01.647

Reputation: 6 391

1"max_concurrent_tabs" does not appear to be in Firefox 40 (2015-08). – Peter Mortensen – 2015-08-16T21:06:33.517

I think the current equivalent of max_concurrent_tabs is the setting in preferences under "General" called "Don't load tabs until selected". – miyalys – 2015-09-19T11:52:37.177

2There is Firefox plugin called BarTab. I assume it does same thing about browser.sessionstore.max_concurrent_tabs – Boris_yo – 2011-05-27T14:24:57.000

1Yes, although I believe it is not updated for Firefox 4. – Mr Alpha – 2011-05-27T15:25:13.313

1

There's a Bugzilla entry on Firefox GC / CC becoming unusually slow.

– RomanSt – 2011-09-25T16:37:31.317

9

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.

Mike

Posted 2011-05-27T13:13:01.647

Reputation: 91

1In 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 – 2015-08-16T21:18:21.690

1

OK, this seems to have changed with Firefox 33 (2014-06), not Firefox 40.

– Peter Mortensen – 2015-08-16T22:01:24.243

2I have Session Manager plugin installed. It also saves sessions allowing better management and customization. What if Firefox and this plugin both update sessions causing high CPU usage and crashes? Is there a way to disable Firefox's session update function and keep Session Manager? – Boris_yo – 2012-03-13T12:07:33.147

4

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.

Matthew Lock

Posted 2011-05-27T13:13:01.647

Reputation: 4 254

2

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.

James Wiseman

Posted 2011-05-27T13:13:01.647

Reputation: 366

Wow, a reasonably sane and civil argument on the internet. Definitely from 2011. – Hashim – 2017-07-04T21:44:12.710

jQuery can have a memory leak? Hrmmmmm – Jeff F. – 2011-05-27T13:38:10.210

1

It can happen. See this list of jQuery bug tickets: http://bugs.jquery.com/search?q=leak&go=&ticket=on. We encountered because we were constantly hitting a single page (through an AJAX request triggered at an interval) that precipitated a fairly large leak.

– James Wiseman – 2011-05-27T13:47:03.583

1Sounds 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) – Jeff F. – 2011-05-27T13:53:26.947

1While 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. – James Wiseman – 2011-05-27T14:02:00.123

1Well 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) – Jeff F. – 2011-05-27T14:08:01.903

@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. – James Wiseman – 2011-05-27T14:18:10.660

na, it's all perspective :P – Jeff F. – 2011-05-27T17:33:20.993

0

If you aren't already doing so, you might try upgrading to the latest Firefox. They've worked hard to reduce those memory leaks.

CarlF

Posted 2011-05-27T13:13:01.647

Reputation: 8 576

I always upgraded and problem stayed. I prefer to live with Firefox 3.6.17 – Boris_yo – 2011-05-30T13:54:40.367