Friday, November 25, 2005

Reducing Firefox's Memory Use?

Federico Mena Quintero proposed a proof-of-concept to reduce Mozilla's memory usage (Firefox is based on Mozilla codes). He used XFree86 on Linux to prove it is possible to reduce Mozilla's memory usage by factor of 5.5.

His method of reducing memory usage is done by dealing with how Mozilla handle images in cache. Right now, both Mozilla and Firefox handle images by uncompressing them and storing them in cache for every open tab. It is designed to give boost to performance (but at the expense of memory). So Quintero proposed to uncompress images and store them in cache, ONLY when the user is looking at the images. Meaning, he proposed to delete uncompressed images and uncompress new images in cache as soon the user scroll away from old images toward new images.

For example, supposed you are looking at a page with 3 large images, and your screen is only big enough for one image at a time. You are looking at image A which is an uncompressed image in your cache. Then you scroll down toward image B. While you are scrolling down, Mozilla will delete uncompressed copy of image A, then uncompress image B for viewing. Then you scroll down even further down to image C. While you are scrolling down, Mozilla will delete uncompressed copy of image B, then uncompress image C. The process are the same when scrolling back up too.

This method successfully reduced memory usage that now (modified) Mozilla doesn't have to keep ALL uncompressed images in cache. Just keep the ones that you are looking at.

However, there are performance hits. Everything you scroll to another image, Mozilla would have to go through uncompressing, painting and deleting processes all over again. Quintero admitted that "Scrolling is a bit jerky if you yank the scrollbar's thumb up and down very quickly. The jerkiness is barely noticeable if you use the scroll wheel or the scrollbar's arrows at about the same rate as you would use while reading a web page."

Unfortunely, some people don't scroll as slow as they read. Sometime I scrolled down really fast just to see what's near the bottom or looking for specific sections (like in Wikipedia or News articles.) So using Quintero's method, it could be painful scrolling down if you scroll down fast or doesn't have fast computer.

But still, it is an interesting read. I am glad to see someone trying to solve Firefox's and Mozilla's memory leak.

No comments: