[cairo] Overhead reduction

Soeren Sandmann sandmann at daimi.au.dk
Thu May 14 09:56:58 PDT 2009


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

> It should be noted that the object pool implementation is not
> thread-safe - if this is inappropriate, modifications will be required
> to use atomic_test_and_inc/dec operators.  Leak detectors might also
> complain about the pools, since they are not drained on shutdown.
> Suggestions on these matters are welcome.

At least in pixman thread-safety is necessary. When used by cairo it
can and will be called from multiple threads. In fact there was an
image pool in pixman for a brief while, but it caused crashes in
multi-threaded applications.

Other than that, an image pool is a good idea, and it would make sense
to add synchronization primitives to pixman, similar to what is in
cairo-mutex-*.h already. If we can track down the contributors to that
file and get them to agree to relicensing to MIT, the code could be
reused directly.

> I'm not sure whether this is the best place to shove an xserver patch,
> but since it goes with the pixman one...  oh well.  :-)

You'll have to send X patches to xorg-devel at lists.x.org. Pixman
patches are welcome at both the cairo and xorg-devel lists.

> diff --git a/pixman/pixman-region32.c b/pixman/pixman-region32.c
> index 8a30d1d..547f358 100644
> --- a/pixman/pixman-region32.c
> +++ b/pixman/pixman-region32.c
> @@ -51,7 +51,8 @@ pixman_region32_copy_from_region16 (pixman_region32_t *dst,
>      
>      boxes16 = pixman_region_rectangles (src, &n_boxes);
>  
> -    boxes32 = pixman_malloc_ab (n_boxes, sizeof (pixman_box32_t));
> +    /* alloca is *much* faster than malloc */
> +    boxes32 = alloca (n_boxes * sizeof (pixman_box32_t));
>  
>      if (!boxes32)
>  	return FALSE;
> @@ -66,7 +67,6 @@ pixman_region32_copy_from_region16 (pixman_region32_t *dst,
>  
>      pixman_region32_fini (dst);
>      retval = pixman_region32_init_rects (dst, boxes32, n_boxes);
> -    free (boxes32);
>      return retval;
>  }

Can we do this with a fixed-size array on the stack instead? If
possible, I'd like to avoid alloca() for the reasons listed in the man
page.



Thanks, 
Soren


More information about the cairo mailing list