Friday, January 22, 2010

Graphics performance in Firefox 3.6

One of the performance improvements included in Firefox 3.6 is a new path rasterizer for use on Windows. This new rasterizer improves vector graphics performance substantially.

The previous rasterizer is designed for a XRender trapezoid model of rasterization. In this model, to fill a polygon, we first tessellate it into a collection of trapezoids. Next, each of these trapezoids is rasterized and the result added to mask image. Finally, this mask is used to composite the filled polygon. This design can work well if we rasterize multiple trapezoids in parallel as could be done on a GPU. However, when we're using the CPU to sequentially rasterize and blend each trapezoid it's not the most efficient approach.

Scanline rasterization is the textbook method for filling polygons and when using a CPU it can be more efficient than tessellating. Instead of breaking the polygon into trapezoids we iterate over each scanline of the mask image. For each scanline, we iterate over the edges that it intersects and fill the pixels in-between the edges to produce the mask image.

M Joonas Pihlaja contributed a scanline rasterizer to cairo as part of a Google Summer of Code project and it's included in Firefox 3.6. This new rasterizer makes a pretty significant difference when filling complex paths. For example, this test draws a spinning map of the world using canvas. In Firefox 3.5, I get about 6-7fps. Using Firefox 3.6, it's nearly 4x faster with about 19-24fps.

7 comments:

Anonymous said...

What's odd is that I get 18-19 fps for about three seconds and then it freezes for about half a second, over and over again. Worth filing a bug over?

Jeff Muizelaar said...

@Anonymous: As far as I can tell the pauses are garbage collection. I filed bug 504640 about that a while ago.

Anonymous said...

I got 1fps better speed in FFox 3.6 than in Chrome 3.0, except for when the GC occurs!

Lars Gunther (itpastorn) said...

Just to clarify. I was one my wife's computer when I wrote the comment about FFox 3.6 vs. Chrome. I have not upgraded yet on my own - hoping that Fedora will give me an upgrade through the default repo. Anonymous 1 and 2 are not the same person.

Unknown said...

On Linux, I get about 14fps on 3.6 (and 3.7pre) versus 7fps on 3.5 so that's a 100% improvement.

However, I get 35fps on Chromium on that same machine, so we still have room for improvement :)

Lars Gunther (itpastorn) said...

It's a known fact that Chrome on Linux is way faster than on Windows. (I wish the same was true for the Fox...)

Jeff Muizelaar said...

@Lars: The Linux situation is kind of tough here. We don't use the new rasterizer on Linux because we do all of our drawing using XRender which of course requires the old approach. Chrome does it's drawing client-side using Skia. This allows it to use a better rasterizer but can make other things more difficult. There's been talk of switching Firefox away from XRender, but no one's had the time to investigate more thoroughly.