Why does Firefox use so much memory?

300 tabs?

DAYUUUUUUUUUUUUUUUUUUUUM

I thought I used a lot of tabs, but that’s a whole nother level.

You are not kidding! But it’s not all laziness. Too many people working as programmers today have not had formal training, and don’t know why they would need it.

I would be very happy if programmers had taken little more than a “combinatorial algorithms” (math or C.S) class and the C.S. prerequisites leading up to it. As to the effect of programmers not knowing the difference between order n and order n**2 (o more) algorithms, I first ran Mozilla on a 4 MB Vax 11/780 which was a one MIP (roughly equivalent to one megahertz) machine , and it ran just barely slower back then than it does now on Intel processors that execute code at least 4000 times faster.

A bit of the difference is due to memory allocation issues, but the majority is due to code being written by multiple people who don’t understand what has already been coded and reinvent the wheel over and over. Also, it seems that the faster machines get, the less incentive people have to write code that is not enormously wasteful of resources, and they either get away with not having had formal software education, or they either forget what they spent a lot of money to learn or, as you suggested, they let laziness keep them from writing good code

A while back, I traced chrome to see why it was racking up so much cpu time when I wasn’t asking it to do anything, and I saw that chrome was issuing non-blocking polls that nearly always returned with none of the polled fds ready for io, but those polls were then followed by the unconditional issuance of non-blocking reads on those descriptors that of course weren’t ready for i/o. As if that weren’t bad enough, the code also calls getrlimi()t millions of times to fetch resource limit values that are obviously never going to change. Still other code calls clock_gettime() and the routine it is supposed to replace, gettimeofday() at least as many times, returning values that are just nanoseconds apart, which implies that the coder is “busy-looping”.

Different threads were misusing the poll(), select(), read(), getrlimit(), gettimeofday(), and clock_gettime() calls at different rates, and some threads were not misusing them all, so a workaround that I tried had to detect when a specific thread should have blocked for at least a short period of time, but was instead hogging the cpu. I intercepted these system calls and replaced them with routines that contained delays using nanosleeo() prior to invoking the real call.

The amount of time nanosleep() slept for was dynamically based on the call frequency of the syscall being intercepted. Since different threads used different calls improperly, the delay rate for a particular syscall was adjusted within the thread, not globally. The more one of these syscalls hogged the cpu, the longer it’s nanosleep time was set to within that particular thread. The result was a truly dramatic reduction in chrome’s load on the system, and much faster chrome response time. Unfortunately, I lost the code to a system failure before doing backups, and I haven’t felt up to spending the time to re-do it.

If you want to write something similar for firefox on linux, OS X, or Solaris, do a man dlsym, noting the use of RTLD_NEXT. You could probably do it on Windows, but I don’t know how.

There is a good (and short) example of redefining the read() system call at
http://mff.devnull.cz/pvu/src/dyn-lib/rtld_next.c

I just put together the following for firefox, but I have not yet tried it.




#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dlfcn.h>
#include <poll.h>

#define	NO_POLL	"ERROR finding real poll()
"

/* This is just a guess.. 
 * try increasing timeout unt il response curve changes direction.
 */

#define TIMEOUT 2   /*  2 milliseconds ( or 2000000 nanosecs */

/* 
* To build and run on Linux, Solaris, or OS X,
*  see http://mff.devnull.cz/pvu/src/dyn-lib/rtld_next.c
*
* For Windows, determine if the equivalent to poll() as used by firefox returns  
* immediately when none of the specified fd's are available.  Also find 
* out whether you can write a function that both has the same name as a 
* library function and can invoke the code of the original library function. 
* If so, use Windows code equivalent to that below.   
*/

int poll(struct pollfd *fds, nfds_t nfds, int timeout)

{
	ssize_t ret;
	char msg[128];
	static int (*real_poll)(struct pollfd *fds, nfds_t nfds, int timeout)
			 = NULL;

	if (!real_poll)
		real_poll = dlsym(RTLD_NEXT, "poll");

	if (!real_poll) {
		/*
		 * This write will fail if fd 2 has been closed,  
		 * but we are exiting,  so who cares at this point?
		 */
		(void) write(2, NO_POLL, strlen(NO_POLL));
		exit(1);
	}

	return real_poll(fds, nfds, TIMEOUT);
}

PaleMoon looks interesting, but from reading the general description on the site, it appears to mostly be optimizations to make it run faster rather than improve the memory footprint – the site states that memory use is “slightly” less than regular Firefox.

But I agree, Firefox memory use is totally ridiculous, and the only thing I can say in its favor is that Chrome is no better. For instance right now I have nothing open except this site, and Firefox has eaten 232,824K of memory and climbing! I could switch to a simple Google search page and it wouldn’t change much. Kids these days just don’t know how to write efficient software!

270MB and all I have open is SDMB. I suspect the entire contents of the board for the last month come nowhere near a tenth of that. You’re right; it’s completely ridiculous.

Nothing new. I’ve been reading the “increased resources just enables sloppy coding” argument since at least DOS 4.0. Certain amount of truth to it, but there is a wide range between hyper-optimization and this kind of pointless bloat.

Why would anyone need that many tabs? Seriously. Am I doing it wrong? 10-12 tabs is a lot for me.

5-6 is a lot for me. I have a couple of monitoring groups I open all at once, about 12-15 tabs each, so I can glance, read and close quickly. If I’m really busy with several projects as well as amusement, I might have 4-5 open. But dozens? Hundreds? Why on earth substitute open tabs for, y’know, a bookmarks list?

Who said anything about ‘need’? It’s dirt cheap to run an enormously powerful machine (with respect to keeping tabs open), so it’s a convenience. I have books and projects that span months to a year or so and there are handfuls of tabs that are easier to keep open than bookmark/whatever to go back to if I need them (colorful tabs add-on makes this even easier).

Looking back, I find a bunch of tabs open for a project that closed months ago. No problem; half a second of closing and it’s over with. Need to find tabs? They’re opened chronologically so it’s no problem skimming through them. They’re easily movable, so if I want to keep something current I can. There are a tab-load of reasons to keep things around, and again, since there’s essentially zero performance hit and there’s minimal effort to find what I’m looking for, there are several upsides and no downsides.

But, of course, YMMV–particularly if you have an underpowered machine and the $50-$100 to bring it up to par is beyond the budget.

I think system power is irrelevant - what on earth is the advantage of keeping vast numbers of tabs open and active instead of simply using a nicely sorted bookmark list? It’s like keeping every jar in your kitchen on the countertops, because two weeks from now you might need a pinch of powdered ginger. Or spreading all your tools on the garage floor so that next week the 10mm box wrench is right at hand.

Different strokes, sure. But I can’t imagine any advantage to using vast numbers of open tabs as a “live bookmark” system.

For reference, I currently have a three-monitor system and it is a rare minute that FF is not open in the left-most, vertical-page one. I am a heavy, heavy browser user for a dozen primary purposes - reference, research, amusement and more. I have probably 3-4,000 bookmarks, 75% of which are current in some sense. So I’m not questioning the practice from the perspective of someone who does nothing but SM and wiki-walking… but I don’ geddit.

Well it was pretty close, but I had to make two minor code changes, and one runtime change.

Now, firefox is not only fast, but is not a CPU hog. It is nowhere near the top of the CPU time list.

In fact, my immediate load average is close to** 0.0** until I start doing something, like loading a page, filling in a form, etc… Then t climbs a bit, but not to the point of excessive CPU use.

The three changes are:

  1. change:**

return real_poll(fds, nfds, TIMEOUT);

to:

if (timeout != -1)
	timeout  += TIMEOUT;
return real_poll(fds, nfds, timeout);**

  1. change
    ** #define TIMEOUT 2**
    to:
    ** #define TIMEOUT 5**

  2. On my 64 bit linux system, the use of LD_PRELOAD_64 when invoking firefox (as per [http://mff.devnull.cz/pvu/src/dyn-lib/rtld_next.c](see http://mff.devnull.cz/pvu/src/dyn-lib/rtld_next.c)) failed to bring in my shared library replacement for poll(). What did work was to just use LD_PRELOAD (with no** “_64”** suffix).

I have to admit my HW is fairly ancient, but an even bigger concern is whether I’ll be able to import my userids and passwords. That’s the main reason I haven’t already given up Firefox. And it’s a tragic thing–Firefox was the browser we all went to, years ago, as a faster and leaner alternative to Internet Explorer.

I quit using Chrome, because it just keeps adding memory and never releases it. I use a lot of YouTube, and every time I would open a video, it would add memory to Chrome, and even when I finished a video and opened a new one, instead of releasing the memory it was using, it just added more, until it ground to a halt.

It’s convenient?

My experience with lots of tabs open is that they shrink in size so you can barely tell what each is for and you have to scroll with the arrows to get to the ones beyond view.

So scrolling with an arrow, stopping a few times to see how close you are, looking at the tabs to try to figure it out if you are near the right one and then scrolling some more is convenient?

Due you have tab navigation plugin/features that allow you to manage 300 tabs in some convenient fashion? Because the out of the box behavior for browsers just can’t be called convenient to manage that many tabs.

Nothing out of the ordinary. Colourful tabs is great, but that’s just a small visual cue and helps keep things separate. TabMixPlus or something lets me set the minimum width of tabs, so maybe that helps–there’s always a favicon and three letters which tells me enough to recognize the site the tab is on. So right now I can see about thirty-five tabs across the top of the screen.

These are all entertainment or fluff tabs, the most recent from a few minutes of checking in on the web. There’s a dinner reservation (Open Table) from last night I know I can close. I’d left it open after making it so I’d have the address/phone number if we needed it. Bookmarking and then closing it would take more time than simply closing it, and reloading the page wouldn’t necessarily bring it back the same information (I’d have to log in again, too).

There are also several news, Dope and Reddit tabs, along with a few YouTube and other sites (probably opened in relation to a thread from the former two). There is some ambiguity about what the actual thread is, but searching tabs is trivial if I’m looking for something specific.

A double-click on the tab overflow arrow moves by ten to fifteen tabs at a clip, so scrolling back to the beginning of even a monster number is an eye blink, so there’s no loss or effort there. And this is kind of key–tabs are already loaded in the browser, so clicking a tab to see what’s in it if it’s vague is an instant process. No need to wait for their servers to respond, for the content to download, etc. So a client calls and I need something that may be scattered across a handful of sites, it’s easy to go back that far and find the set. And again, because they’re pre-loaded, I don’t have to wait at all sifting through the list.

When I have the time/inclination, I’ll go back and cull the list, close-close-close-keep-close-close-ooh,thislooksinterestingletmereaditnow-close-close-keep-keep…
Bookmarking/deleting the bookmark is, to me, more work than just leaving the tab open. I’d still have to open and close the tab anyway, so there’s no time savings there. I’d also have to create and then delete the bookmark, extra work I don’t have to do. The convenience of tabbed browsing that makes it nice to have ten tabs scales up very nicely.

Ok, with all these complaints about Firefox and Chrome, is there a browser out there that DOESN’T have these memory usage and speed problems? I switched from Firefox to Chrome a year or 2 ago, but Chrome really isn’t any better.

Thanks,
J.