[cairo] 10000% performance increase for clip surfaces

Alexander Larsson alexl at redhat.com
Fri Dec 17 06:57:48 PST 2004

I'm playing around with cairo by making an xpdf backend that uses cairo
for rendering. When i tried it on a pretty simple page i got really
horrible performance. Rendering took about 4 minutes and 30 seconds.
Each glyph took like a second to render.

The problem is that the pdf set a clip rect for the whole page that
wasn't pixel aligned, so we always used a clip surface instead of a
quicker clip region. In various places when drawing using a clip surface
cairo allocates an intermediate surface. However, cairo always allocates
the full size of the clip surface (in my case 1240x1754) for this
intermediate surface, even though the drawing might not need all of
that. The clearing and compositing of this intermediate surface for each
glyph was taking a lot of time.

When I fixed this in cairo it was still using a lot of time initializing
the clip and intermediate surfaces, and i realized that initializing
solid fill for the intermediate surfaces was using the full generic
compositing function, so I finished the solid-rect fill support in

These two changes brought down the page rendering speed to about 2.4
seconds, which is about 11250% faster (likely even more, since a
significant part of the time is spent reading and decoding the pdf and
writing out the resulting png).

Cairo and Pixman patches are attached. Please check them out, as this is
the first time ever I've looked at the code.

 Alexander Larsson                                            Red Hat, Inc 
                   alexl at redhat.com    alla at lysator.liu.se 
He's an unconventional arachnophobic romance novelist plagued by the memory of 
his family's brutal murder. She's an orphaned Buddhist research scientist 
married to the Mob. They fight crime! 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pixman-performance.patch
Type: text/x-patch
Size: 6205 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20041217/54e45d2b/pixman-performance.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cairo-performance.patch
Type: text/x-patch
Size: 16061 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20041217/54e45d2b/cairo-performance.bin

More information about the cairo mailing list