[cairo] Overhead reduction

Jonathan Morton jonathan.morton at movial.com
Fri May 15 02:27:33 PDT 2009


> > 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.

Okay, that's useful to know.  An atomic-test-and-inc routine should be
roughly the same speed as a plain i++ on most modern hardware, it just
needs to be implemented properly, which is an utter pain.

> 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.

Shall I leave you to that part?  I can probably fix up the patch to use
the primitives once the licensing is sorted out.

> 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.

It seems that it's strictly speaking a variable-size array, because it's
handling a general case.  But most compilers probably don't support the
dynamic-sized array syntax that GCC does, which would be the cleaner
alternative to alloca() otherwise.

Perhaps using a fixed allocation on the stack would be appropriate for
the common case(s) which use very low numbers, and falling back to
malloc for the general case.

-- 
------
From: Jonathan Morton
      jonathan.morton at movial.com




More information about the cairo mailing list