LWN.net Logo

Off by an order of magnitude?

Off by an order of magnitude?

Posted Jul 27, 2007 14:36 UTC (Fri) by Los__D (guest, #15263)
In reply to: Off by an order of magnitude? by man_ls
Parent article: Still waiting for swap prefetch

Yeah we do, but does it really cache a bitmap of the page? That would seem a bit silly


(Log in to post comments)

Bitmap cache

Posted Jul 27, 2007 21:57 UTC (Fri) by man_ls (subscriber, #15091) [Link]

Yeah we do, but does it really cache a bitmap of the page?
I don't know exactly, but I would say it does. Loading a couple of big JPEG files takes quite longer than changing tabs between them.
That would seem a bit silly
Why, exactly? If you have the RAM to spare, it seems to be as good as any other use. I seem to remember some discussion on LWN about Firefox caching even pages in the history.

When people complain that "Firefox eats up 2 GB" in a 4 GB machine, it gives the wrong impression. Firefox runs fine on my 128 MB laptop, and memory seldom goes above 80 MB.

Bitmap cache

Posted Jul 28, 2007 13:38 UTC (Sat) by Los__D (guest, #15263) [Link]

I would never (never EVER) suggest using JPEG for computer graphics, but caching in PNG would seem smarter than a bitmap, and not really that much slower. Of course, when you only have 3-4 tabs, it wouldn't really matter, but as the count goes up, you can much better afford the CPU than the memory. Plus, the CPU is only when you change, the memory usage is constant.

I'm not completely sure how uncompressed PNG would handle the JPEG's on the page, but I couldn't imagine it getting worse (memory wise) than bitmap, just equal. (I've been known to be naive in my expectations from formats though).

The browser (toolkit?) could of course also do some kind of checking of available memory, and change algorithm from that, but maybe that is an unneeded complexity.

I don't know, maybe it's easiest/simplest and mostly correct to just keep the rendered pages as is in memory, but for some usage patterns, it does become a huge waste of memory.

Bitmap cache

Posted Jul 28, 2007 13:51 UTC (Sat) by man_ls (subscriber, #15091) [Link]

I would never (never EVER) suggest using JPEG for computer graphics
I wouldn't either. My little experiment with JPEG images involved decompressing a JPEG image vs. caching an uncompressed bitmap. Caching images in a lossy format would be ludicrous.

But caching in a lossless format such as PNG isn't such a good idea either. An important aspect of caches is that you should store an artifact which you already have, not one you have to generate. If you have to compress a bitmap to PNG before caching it, you are wasting a lot of CPU time just to generate a cache which you might as well never use again.

An example: you download a JPEG image, then uncompress it to show it, and then you compress it to PNG before caching it in memory. Messy.

Bitmap cache

Posted Jul 28, 2007 14:00 UTC (Sat) by Los__D (guest, #15263) [Link]

It really depends on the cost of CPU vs. the cost of memory.

For most usage patterns, I agree, but for those that likes to have 30+ tabs open (for some reason), caching the uncompressed bitmap is a _big_ waste.

The question is if the best approach wouldn't be to just forget or limit those caches for that kind of usage. At least the bitmap approach is asking for disk trashing.

Bitmap cache

Posted Oct 9, 2007 18:49 UTC (Tue) by Blaisorblade (guest, #25465) [Link]

I've read time ago a comment from a OLPC developer on exactly this issue. I'm writing a summary of his comments I recall.
Basically, an application can store an uncompressed bitmap in the X server. And Firefox caches all images this way! That's the problem. Probably avoiding the caching would be even faster (due to no swapping).

IMHO (and this is my opinion, I don't recall his one) a reasonable solution would be to extend the X protocol to allow caching compressed images in most reasonable formats (including especially JPEG). Then the X server can keep a cache of most shown decoded images.

Since the JPEG compression ratio is huge, there would be a huge gain from this.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds