144 points · by saulrh · 15y ago · 94 comments
I remember a profiling of a gnome startup. It touched something like insane like 40K files. Another profile I saw removed a few bytes (unneeded, it wasn't some complex optimization) from some commonly used datas-tructure for an 50%+ speed improvement.
Simply we're being cut to death by bloat and pure, sheer lazyness. a web browser has absolutely no excuse for using 500megs of ram. None. Whatsoever.
I expect this comment to fall on deaf ears.
• It's not even on topic. This post is not about general memory usage; it's about fragmentation in the javascript VM – i.e. that a system object existing in a general memory page precludes that page from being garbage collected / deallocated even though the lifetime of system objects is very different. This is not a trivial matter for which the only explanation is laziness.
• It's spoken like someone who's never seriously worked on a large open source project. Memory profiling and leak tracking is done widely and often (using valgrind, mostly).
• You speak as if you know how much memory a web browser should use. How do you know? Have you worked on modern web browsers? Or are you just, as I assume, by fiat deciding that 500 MB is too much?
• There's very often a speed / memory usage tradeoff. At present, especially for web browsers, users tend to prefer speed. (i.e. how many rendered pages do you cache per tab so that clicking the back button is next to instant?)
• The right time to profile and optimize is usually later in the development process. We all know the famous quote. Optimizing early tends to lead to ugly code that, amusingly, is harder to optimize later.
But this much I can say, that even a few years back I could comfortably use a Linux desktop on 64MB RAM. Now even a Debian box with X would run rather choppily on a system that has 256MB and it is not very clear to me in what exact way is my compute experience better now than the one that I had on the 64MB system. Even those that are considered a lean browser, take upto 200MB of that 256 and still does not work smoothly.(FF 3.5 still does fine on this system BTW). Had my old system been augmented with some 3Gigs of RAM it is possible that its performance would be worse than a modern system of equivalent RAM, but now that it is common for a system to occupy more resources to accomplish the same level of activity is at times an irritant.
The usual counterargument is that RAM is cheap and one should just go and buy some or suffer otherwise. I think it is this assumption that is made or a requirement that is imposed by the newer versions of software that GP was complaining about.
Today's agony always seems new and fresh, but it never is. I still have some of those old systems sitting around to remind me. The "good old days" were pretty miserable.
Today I have Linux and Firefox and the exact same problems -- in 1G of RAM, which is a comparably low-spec system today to what the Indy was back then. The more things change, the more they stay the same.
This is a good point, and the amount of memory used for such a cache is ideally "all of it, but no more".
Which is the same argument for buffer cache.
So I wonder if it's possible to use the buffer cache in this way?
Perhaps write the rendered image to a tmpfile. Then don't sync the write and also something like fadvise(FADV_DONTNEED). The app can then free the memory. (Clearly you could play a similar game with mmap()).
The idea would be to have the memory sitting in the system buffers. But the app can inform the system that these pages are discardable under memory pressure, rather than needing to be written to disk.
Writing that to disk involves either fixing up all the pointers on read or making sure you can read it all back into _exactly_ the same locations in your virtual address space or something. This can still improve performance over creating the object graph from scratch (c.f. XDR for Gecko's JavaScript or Mozilla's fastload stuff for the user interface), but not nearly as much as just having the object graph there.
One other note: just because _you_ don't sync the write doesn't mean some other random part of your app, or some other app, won't.... and then you have extra disk traffic.
And yet Firefox seems to use about 4 or 5 times more memory than Chrome on my system whilst being noticably slower as well...
If Chrome had all the addons that Firefox had, Firefox would be a dead browser.
I still use Firefox as my primary browser. For now.
Since then I stopped accepting expert opinion blindly.
Where memory leaks (or pretty much any performance metric) are involved, the more sure someone sounds, the less likely they are to be an expert unless they have done extensive measurements to back up their claims.
That's not to say Firefox's memory usage is perfect, far from it. That's why we're making improvements like this one. See https://wiki.mozilla.org/Performance/MemShrink for more.
I use a similar version of your processes. adding: when code complete examine the footprint and speed, and diligently explain to myself where the time/memory went. If it was wasted, do something about it immediatley.
[1] http://www.phatcode.net/res/224/files/html/ch39/39-01.html
Yet there's 500mb, right there. Never? Whatsoever? I don't think so.
Compressed. Remember that in order to display it, the browser has to unpack it to what amounts to a bitmap. And newer, better compression formats (e.g. PNG) make that even worse in compressing the same bitmap file to a much smaller transmission size.
A 1024x768 32-bit image is 1024x768x4 = 3.145.728 bytes when uncompressed.
All these memory leaks being fixed are "pure, sheer lazyness"?
https://bugzilla.mozilla.org/buglist.cgi?keywords=mlk%2C%20&...
You don't know how people use their browsers.
For example, I have 8 tab groups open right now, each with 5 - 20 tabs. Let's say that's about 75 tabs. That's only 6.67MB each to fill 500MB. I'm regularly over a 1GB. I'm sure a significant part of that is actually memory leaks, but that's beside the point.
This would, of course, slow down browsing when switching from tab to tab, since the entire page would need to be reloaded. But I would gladly give up some speed for memory on my old machine with only 3.7 gigs of RAM.
Before anyone asks why don't I just use bookmarks in the first place, let me say that I prefer the organization that tabs give me for pages I am currently working on. I do move those tabs to bookmarks if I use them long enough. But in the relatively short term I prefer tabs.
Another option that would be a compromise between the solution proposed above and keeping all tabs in memory would be to keep only the N most recently accessed tabs in memory, and treat the rest as bookmarks. That would make switching between those N tabs relatively responsive, but still use a lot less memory than having every page for every tab reside in memory. Especially for people like me, who regularly have over 100 tabs open.
Of course, the value of N should be user-configurable. With a N=1, the second proposed solution would be equivalent to the first.
So they're basically saying one of the reasons a copy of Firefox with no open tabs is currently consuming 1GB of my computer's memory is because they didn't want to suck on benchmarks. Is there a flag I can set to tell the damn browser "I AM A REAL USER AND NOT A BENCHMARK, PLEASE DON'T SIT ON 1GB OF MEMORY, FREE IT IMMEDIATELY"?
We're working on improving things. See https://bugzilla.mozilla.org/show_bug.cgi?id=656120 for another big improvement that will go into FF7.
For reference: 24G of DDR3 costs about $220 these days.
If a process needs (or pretends to need) that much memory, the swapping will just kill the performance, and the machine gets unresponsive. I rather have the OOM killer do its job, have a few processes dying and be able to continue using the machine.
As far as I'm aware, there's no other method to disable the default Windows behaviour of swapping out programs even when sufficient RAM is available.
But still, the app has to run on real machines today. So its worth a "sweeping up" pass before release, to fix gross oversight and bugs that leak/use CPU egregiously.
Could explain their recent flurries of rewriting the javascript jits.
[1]: https://www.ohloh.net/p/firefox/analyses/latest [2]: http://www.ohloh.net/p/chrome/analyses/latest
> Memory fragmentation is just as bad as memory leaks.
Indeed.
This is the real problem then - benchmark score vs real-world useabilty.
FF6 has already been frozen and released to the Aurora channel; it goes to Beta tomorrow. FF7's code gets frozen and released to Aurora tomorrow.