News for hackers. Stuff that matters.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by mnarayan01 on Tuesday October 01, 2013 @08:03AM (#6475549)
Like many of the other Firefox memory changes, this one leaves me feeling a little ambiguous. On the one hand, obviously keeping memory usage down is good. On the other hand, waiting to decompress/decode images until they are visible to the user means that there are obviously going to be performance trade-offs (and also, obviously, design/engineering trade-offs).

Speaking just from my personal usage: I don't think there has ever been a time where delaying the image decompression on a page would ever have had any utility for me (at least from a memory standpoint). On the other hand, there have been plenty of times when eagerly performing image decompression would make my browsing a bit smoother.

All in all, it seems (from a not-particularly-in-touch outsider perspective) as if Mozilla went from being totally dismissive of memory complaints to being hyper-responsive to memory complaints with no (publicly stated) rationale behind the change. It would be interesting to see the reasoning behind this (if only from an intellectual standpoint), particularly given that in many cases I tend to feel that it would have been better to simply be a bit more diplomatic when rejecting memory-based bug reports.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by Lagged2Death on Tuesday October 01, 2013 @11:58AM (#6476980)
...it seems ... as if Mozilla went from being totally dismissive of memory complaints to being hyper-responsive to memory complaints with no (publicly stated) rationale behind the change.

I don't know what their internal rationale is.

"Memory is cheap," we like to say, but it's really only true if you're not wasting it like crazy all the time. Ten years ago you could surf the web with 512MB of RAM; now we're getting to the point where 4GB isn't considered enough. If 4GB now costs the same as 512MB then, then in the sense of "dollars worth of memory required to perform function X acceptably," memory hasn't actually gotten any cheaper.

If you can get performance that used to require 4GB down into 1GB, you've upgraded the performance of a bunch of older and low-budget devices from "barely usable" to "fine."

Take the big-picture view: updates like this can actually result in a slower flow of "obsolete" computers and devices into the landfills. This is one of those bottlenecks where a little good engineering can have really disproportionate positive aggregate effects.

This sort of thinking has been one of the selling points of desktop Linux for a long time. I wish Microsoft thought more like this.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by mindcrime on Tuesday October 01, 2013 @04:09PM (#6478756)
Right. Also, no matter how cheap memory is, you run into limits of things like maximum RAM capacity. I'm there now... I have 8GB of RAM in this laptop, and that's all it can hold. I can't spend more money to put more RAM in here even if I want too, as it just won't take it. I'd love to go up to 16GB, but that won't happen until I buy a whole new machine.

Needless to say, I'm very happy about this firefox news. AS somebody who routinely runs a lot of apps (and more than a few memory hungry ones) I want every app to be a freaking memory frugal as it possibly can, and be a good citizen when RAM has to be shared between apps.

Playing the whole "Unused RAM is wasted, take up as much RAM as you can" mindset is fine if you only run one app at a time, but, really, who the f%!# actually does that???

Re:Firefox fixes save gigabytes of memory on image-heavy pages by AshleysBrain on Tuesday October 01, 2013 @08:44AM (#6475704)
If image decoding is asynchronous (don't know - guessing it is already?) and you decode them when they get near to the viewport and not just when they become visible, then it should always be decoded by the time you scroll to it and yet never jank the page. Scrolling a long way really fast probably means there's a small delay while it decodes images, but surely that's worth it to save gigabytes of memory?
Re:Firefox fixes save gigabytes of memory on image-heavy pages by mccr8 on Tuesday October 01, 2013 @09:07AM (#6475812)
Image decoding in Firefox was recently made multithreaded.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by mnarayan01 on Tuesday October 01, 2013 @09:33AM (#6475960)
> but surely that's worth it to save gigabytes of memory

I'm not sure _save_ is the right word here...using available memory has no particular cost to me over not using it. Of course, the _available_ modifier is relevant, so I take your point.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by scholia on Tuesday October 01, 2013 @09:46AM (#6476052)
It's a huge advance for those of us who usually have 50-60 tabs open for weeks at a time, where hitting a really heavy image page would tip Firefox over the top and crash it.

I switched from Chrome to Firefox a couple of months ago for its ability to handle more tabs without slowing/crashing, and for its better performance with image-heavy pages. So, for me, it's not just "who cares?" it's a killer feature.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by Touche on Tuesday October 01, 2013 @10:48AM (#6476522)
Tabs are not bookmarks. Use bookmarks.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by dbaupp on Tuesday October 01, 2013 @10:55AM (#6476568)
Why should one use bookmarks rather than many tabs? I have many concurrent projects going, and things I refer to regularly, so I just leave them grouped in my tree of tabs on the sidebar. Much more efficient than digging through nested bookmark menus, or trying to make sure the bookmarks are properly classified.

Basically, my tabs are bookmarks, except tabs are integrated into the web-browser better.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by dragonwriter on Tuesday October 01, 2013 @12:08PM (#6477044)
So, the problem is that the bookmark UI design is broken.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by dbaupp on Tuesday October 01, 2013 @01:02PM (#6477436)
My bookmark UI isn't broken: putting tree-style tabs in a sidebar is perfect.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by jlgreco on Tuesday October 01, 2013 @02:27PM (#6478103)
If they would make the tree-style tabs very aggressively swap to disk, or even discard state entirely and seamlessly become a bookmark that would reload when clicked (perhaps this behavior could work only for white-listed domains, like wikipedia.org), that would be perfect.

The main usability problem with bookmarks over tabs AFAIC is that the bookmark UI does not encourage pruning bookmarks, so most become stale over time.

Another idea I've been kicking around for a while is "tab decay". Have tabs start to decay and close themselves after not being viewed for a configurable amount of time. 1 month would probably do it for me, it would save me a lot of cleanup time.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by dragonwriter on Tuesday October 01, 2013 @03:01PM (#6478342)
I'm saying that the description recommends using tabs in place of bookmarks because the bookmark UI is suboptimal.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by Touche on Tuesday October 01, 2013 @12:30PM (#6477201)
> Why should one use bookmarks rather than many tabs?

Because, as the parent posts point out, tabs take up memory and can cause the browser to become sluggish.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by jeltz on Tuesday October 01, 2013 @03:21PM (#6478473)
Yes, that is true but there is no problem with just 60 tabs. I have 260 open tabs and my browser is not sluggish and the memory usage isn't too bad either, 3GB.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by showsover on Tuesday October 01, 2013 @10:57AM (#6476582)
Bookmarks don't save state, which is especially annoying in a time where async calls are used so heavily.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by mnarayan01 on Tuesday October 01, 2013 @11:31AM (#6476808)
And then we have people complain that their "un-used" tabs are taking up too much memory, so browser makers cut down on the level of state stored in the tab and that brings us to the current point.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by DennisP on Tuesday October 01, 2013 @11:59AM (#6476984)
So store the state on disk if the user hasn't been to the page for a while. When I've I last visited a tab three days ago I don't mind a little disk delay when I get back to it, in exchange for not having disk churn everywhere when I'm trying to get work done.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by Touche on Tuesday October 01, 2013 @12:31PM (#6477205)
A URL should contain all of the state needed. If it doesn't then it's a poorly designed website.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by jeltz on Tuesday October 01, 2013 @03:22PM (#6478481)
URLs do not contain scroll position on the page.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by FeepingCreature on Tuesday October 01, 2013 @01:29PM (#6477649)
Firefox has to work with the internet as it is, not the internet as we wish it were.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by Touche on Tuesday October 01, 2013 @02:01PM (#6477901)
So do users. Keeping several dozen tabs open indefinitely decreases the stability of every browser. Computers have resource limitations. 95% of websites have bookmarkable links; use them.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by jeltz on Tuesday October 01, 2013 @03:24PM (#6478490)
Not Firefox, which is why I use it instead of Chrome. I am not saying tabs are without problems but they fit way better into my usage patterns than bookmarks.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by sanskritabelt on Tuesday October 01, 2013 @01:16PM (#6477535)
This, I claim, is ideology.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by jlgreco on Tuesday October 01, 2013 @02:22PM (#6478067)
> Use bookmarks.

Who said he doesn't?

Re:Firefox fixes save gigabytes of memory on image-heavy pages by dragonwriter on Tuesday October 01, 2013 @12:06PM (#6477028)
> I'm not sure _save_ is the right word here...using available memory has no particular cost to me over not using it.

The browser not using available memory means that other processes on the system have the memory available to use. For those of us who may have the browser running while something else is actively running on the computer, that's potentially pretty important.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by sliverstorm on Tuesday October 01, 2013 @02:25PM (#6478088)
You would be right if Firefox's memory usage was opportunistic, like the OS disk cache. Problem is, Firefox (or any browser for that matter) will tend to bloat in memory as it sees fit, which for any device with 4GB or less of RAM may mean swapping to disk, which is still the same killer as it always has been.

4GB seems to be the threshhold right now. Windows consumes maybe 0.5-1GB, budget 0.5-1GB for a handful of other programs, bloat Firefox up to 1-1.5GB, and suddenly you're swapping. (Naturally the OS does not wait right up until you have 4GB of RAM consumed to start swapping, it seems to start around 3GB)

Re:Firefox fixes save gigabytes of memory on image-heavy pages by joosters on Tuesday October 01, 2013 @09:59AM (#6476158)
Image decompression is pretty easy, CPU-wise. Well over a decade ago, computers were happily rendering JPEGs on-the-fly without storing a decompressed version (RISC OS apps did this). Your desktop/laptop/phone has plenty of ability to do this.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by sanxiyn on Tuesday October 01, 2013 @08:29AM (#6475649)
https://wiki.mozilla.org/Performance/MemShrink has some reasons. One reason is explicitly "Fewer people will complain that Firefox is a memory hog and that Mozilla ignores memory usage". Even if complaints are technically nonsense, addressing complaints is still important.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by mnarayan01 on Tuesday October 01, 2013 @09:21AM (#6475889)
Good link...thanks.

> Even if complaints are technically nonsense, addressing complaints is still important.

Totally true, but I don't have to like it...and I can fight against it by complaining about the addressing of the complaints!

Re:Firefox fixes save gigabytes of memory on image-heavy pages by badman_ting on Tuesday October 01, 2013 @11:26AM (#6476768)
And thank goodness for that.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by NathanKP on Tuesday October 01, 2013 @09:19AM (#6475873)
We've been using stuff like Infinity.js (http://airbnb.github.io/infinity/) for quite a while now, and it's basic functionality is to improve long scrolling panes by dynamically adding and removing elements (including images) in real time as you scroll to keep the number of elements low and the page responsive. Sites that use this technique usually feel just as responsive as if the site really did have a page with 10,000 items on it instead of a dynamic viewpoint that only shows 100 items as a time.

Personally I think it would be best if HTML developed a spec for an official UITableView style native element. That would provide a way to solve the memory issues and avoid the need for JavaScript hacks like Infinity.js

But in the meantime browser workarounds like this one from Firefox will help avoid the huge memory usage in sites that don't use smart techniques like Infinity.js

Re:Firefox fixes save gigabytes of memory on image-heavy pages by swift on Tuesday October 01, 2013 @02:44PM (#6478220)
I don't know that I'd characterize this as a workaround. Infinity.js is definitely a good approach, but you should expect good baseline performance from the browser even without more complicated techniques.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by NathanKP on Tuesday October 01, 2013 @03:49PM (#6478639)
I expect good baseline performance from a combination of both the HTML and JavaScript code of the page, and the browser. Sure it's nice if the browser does some tricks to make a badly written page that has 2 GB of image data on it play somewhat more nicely on the system, but if that page loads badly its not the browsers fault, its the fault of the web developer who didn't paginate, or use Infinity.js or something like that.

The reason why I call the Firefox fix a workaround is because the proper way to solve the problem of 2 GB of image data on a page is by using a UITableView style wrapper.

But HTML 5 doesn't have such an element for us to make use of. The proper fix would be to add such an element to HTML itself, but obviously that's something that takes years to do and to get it adopted across all browsers.

So in the meantime tricks like what Firefox is doing are nice to help prevent inexperienced web developers who create abominably inefficient webpages from consuming too much system resources when an unfortunate victim downloads the page.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by swift on Monday October 07, 2013 @06:07PM (#6511637)
Honestly, this is pretty similar in effect to a UITableView-style wrapper, except that it's handled automatically by the platform. Sophisticated JS-only webapps are perhaps a different case, but a site that consists primarily of HTML and CSS should work just fine across a variety of different devices with different performance characteristics and memory capacities, automatically. This is one of the advantages of a declarative model like HTML/CSS: it gives the implementation a lot of freedom to apply optimizations and adapt to the limitations of the platform it's running on.

I guess what I'm trying to say is that this isn't a workaround - it's one of the primary reasons HTML and CSS are architected in the way that they are. This has nothing to do with helping inexperienced web developers and everything to do with preserving the declarative nature of basic web content.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by nnethercote on Tuesday October 01, 2013 @06:18PM (#6479418)
Have you tried the new version? You should try it before you dismiss it due to theoretical concerns. As I wrote in the blog post, the time before the page displayed dropped from 5 seconds to 1 seconds. And scrolling performance is unaffected AFAIK; if you have evidence otherwise Timothy and I would love to hear about it.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by illumen on Tuesday October 01, 2013 @10:31PM (#6480263)
Firstly... thanks! I love firefox, and appreciate any memory savings.

Did you do any tests for animation performance, and test that preloaders are not affected? Are these issues addressed?

Hardware accelerated decoding(like IE, and image viewers use) would help. Much modern hardware can do the whole decode-resize step in dedicated hardware.

For software only, an improvement is resizing in jpeg-space to the exact size required. It is much faster than decoding the entire jpeg (eg 5 megapixels 2MB jpeg, into 20MB of uncompressed image data) then only displaying it at 320x200 pixels(1MB at the 16bit needed for this YUV data). You can resize the smaller jpeg-space data, then not have to allocate that 20MB of data (perhaps never going back to the OS).

As well, some images compress very nicely with hardware texture compression (but many look awful). There are heuristics that can be used to decide the best type of texture to use based on the image data.

Why turn 6bit-16bit per pixel jpeg data into 32 bit per pixel data? It only takes more memory and is slower to draw. Surely jpeg usage is common enough to special case its handling?

Good luck!

Re:Firefox fixes save gigabytes of memory on image-heavy pages by driverdan on Tuesday October 01, 2013 @09:40AM (#6476024)
The article states that it reduces initial page load time by about 4 seconds. Load time is far more important than a few ms here and there to load images on the fly when they are needed.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by akjj on Tuesday October 01, 2013 @08:59AM (#6475770)
This was a follow-up to an earlier change which also delayed image decompressing. In the description of that change the author wrote: "Andrew McCreight wrote a comment that I can’t find now, but basically he said that on one of his machines, that page was extremely slow and painful to scroll through before the change, and after the change it was smooth and pleasant."

If you have any examples where the linked changes causes performance degradation, you should try reporting it to the developers.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by smackfu on Tuesday October 01, 2013 @10:47AM (#6476514)
I assume the old way choked very badly once you ran out of real RAM.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by dkhenry on Tuesday October 01, 2013 @08:56AM (#6475758)
I have been running aurora for a while so I already have this fix. I just tested it and there was no noticeable performance impact for the memory saved.

Chrome on the other hand used all my memory and caused me to start swapping. Any website with lots of images loaded will be impacted by this ( facebook , G+ , tumblr , ... ) so I think its a rather important change

Re:Firefox fixes save gigabytes of memory on image-heavy pages by dbaupp on Tuesday October 01, 2013 @08:17AM (#6475610)
I imagine it's good for image heavy sites like Pinterest or Tumblr.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by mikebonnell on Tuesday October 01, 2013 @10:20AM (#6476318)
Agreed, it's a huge win there.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by daleharvey on Tuesday October 01, 2013 @08:22AM (#6475630)
With the capbility being built, if there is a performance tradeoff (I didnt look through the bugs, but imagine it was already thought about), then its now possible to do 'hey you have a load of spare memory' pre decode all the things type optimisations
Re:Firefox fixes save gigabytes of memory on image-heavy pages by mnarayan01 on Tuesday October 01, 2013 @09:24AM (#6475907)
Good point. I imagine the issues would be more with when to unload an image, though depending on the implementation that might not be particularly problematic either.
Re:Firefox fixes save gigabytes of memory on image-heavy pages by dragonwriter on Tuesday October 01, 2013 @12:05PM (#6477020)
> All in all, it seems (from a not-particularly-in-touch outsider perspective) as if Mozilla went from being totally dismissive of memory complaints to being hyper-responsive to memory complaints with no (publicly stated) rationale behind the change.

I suspect that being a company that wants to have a unified code base for their browser and that is now newly pushing a browser-centric OS for smartphones may explain this, at least in part.

Re:Firefox fixes save gigabytes of memory on image-heavy pages by nnethercote on Tuesday October 01, 2013 @06:16PM (#6479407)
I first started working on improving memory consumption in early 2011, and that evolved into the MemShrink project (https://wiki.mozilla.org/Performance/MemShrink) a couple of months after that. Firefox OS came later.

In fact, it's fortunate that MemShrink had been up and running for a while because it meant we had already fixed a lot of leaks and inefficiencies, and we had good tools for identifying memory problems in Firefox OS.