[cairo] Performance issue with the PDF backend

Adrian Johnson ajohnson at redneon.com
Sun Dec 2 05:11:28 PST 2007


Emmanuel Pacaud wrote:
> Hi,
> 
> We're facing a performance issue with the cairo PDF backend (cairo 1.5.3).
> 
> The next stable version of gnumeric will use GtkPrint instead of
> GnomePrint, which mean it will use cairo for the print to PDF file
> capability. But, comparing to the PDF files generated by gnome-print,
> cairo produces bigger files which are rendered very slowly by either
> evince or acroread.

There is not a lot of difference in file size (253k vs 238k) and further
work is planned to reduce the file size. I can reproduce the slow
rendering with Evince and Acroread 7. Acroread 8 does not have the slow
down.

> Gnumeric, when rendering spreadsheet cells, clip each cell content by the
> cell area. Here's a sample of the cairo output if the clipping is
> completely discarded:
> 
> http://emmanuel.pacaud.free.fr/bugs/cairo/gnumeric-cairo-1.5.3-unclipped.pdf
> 
> It looks like we could try to be smart at the gnumeric printing code, and
> to clip only when needed.
> 
> But I'm wondering if the situation could be improved in cairo itself. Or
> if it exists a workaround that would avoid the inefficient files.

The problem is caused by the new PDF file structure used to support
finer-grained fallbacks and push/pop groups. To avoid using a temporary
file the current content group is closed and a new group created each
time a pattern needs to be written out. However the problem with this is
that drawing a group performs an implicit save/restore so any clipping
inside a group will be lost when a pattern is written and a new group is
 started. To work around this each time a clip is required the group is
closed and the clipping is done in the parent group. When a very large
amount of clipping is done as is the case in gnumeric the slow down
becomes noticeable.

The solution to this is to not interrupt groups to write out patterns
until the end of the page. Instead all the patterns can be written out
after the page content has been written. All the clipping can then be
done in the same group.

I was planning to do this change after 1.6 as part of the larger task of
ensuring that cairo does not embed the same pattern more than once. I'll
have a look and see how hard it will be to fix this in time for 1.6.




More information about the cairo mailing list