[cairo] Overhead reduction

Soeren Sandmann sandmann at daimi.au.dk
Thu May 21 06:19:44 PDT 2009


Jonathan Morton <jonathan.morton at movial.com> writes:

> Attached are a pair of independent patches which implement the above two
> optimisations.
> 
> The region32 patch is platform-independent and fairly trivial.

I have pushed that patch with some formatting changes and 16 temp
boxes instead of 4.

> The image patch, which implements an object pool, is probably more
> controversial and certainly a lot bigger.  However, under my tests it is
> very very nearly as fast as the previous unprotected stack, while being
> threadsafe (unless there are bugs I haven't spotted).  The object pool
> should be reusable for other fixed-size objects without change.

First, all this image creation activity comes from the X server, which
creates and destroys up to three pixman images per Render request. I
think the best way to fix this would be to keep one pixman_image_t
around per Render Picture, and just update it as the Picture
properties change. This is a fair amount of work in the X server, but
it avoids not only the malloc() overhead, but also the initialization
of all the fields in the image.

That said, I do think an image pool makes sense, but since
pixman_image_t is the only dynamically allocated, fixed-size object we
have at the moment, a complete framework for object pools feels like
overkill to me.

Is there a reason we can't just use thread local storage? It seems all
compilers we care about support either __thread or declspec(thread).
In my limited testing on a P4, the overhead of using a thread local
variable seemed to be on the order of 100 cycles, which considering
everything else going on during image allocation, really isn't a big
deal.

There is the beginning of a patch here:
        
        http://www.daimi.au.dk/~sandmann/tls.patch

To make it committable, there would have to be configure checks for
__thread/declspec(thread) and fallbacks for when we don't have them.


Thanks,
Soren


PS:

> +/*
> + * Copyright © 2009 Movial Creative Technologies Oy
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that
> + * copyright notice and this permission notice appear in supporting
> + * documentation, and that the name of SuSE not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  SuSE makes no representations about the
> + * suitability of this software for any purpose.  It is provided "as is"
> + * without express or implied warranty.
> + *
> + * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
> + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
> + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
> + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + *
> + * Author: Jonathan Morton <jonathan.morton at movial.com>
> + */

The preferred copyright notice for new code is the one in COPYING,
which avoids naming the copyright holder explicitly in the warranty
disclaimer. 


More information about the cairo mailing list