[cairo] _cairo_pattern_create_copy()

Behdad Esfahbod behdad at behdad.org
Thu May 1 08:41:27 PDT 2008


On Thu, 2008-05-01 at 14:45 +0100, Chris Wilson wrote:
> A few months ago, Adrian Johnson committed this patch:
> commit b4e0864b960887fd71de85d514cb3e855c276080
> Author: Adrian Johnson <ajohnson at redneon.com>
> Date:   Mon Jan 7 20:42:15 2008 +1030
> 
>     Use _cairo_pattern_create_copy() in cairo-surface.c
>     
>     Use _cairo_pattern_create_copy()/cairo_pattern_destroy() instead of
>     _cairo_pattern_init_copy()/_cairo_pattern_fini() so the PDF backend
>     can reference the patterns and destroy them later.
> 
> Profiling memory allocations for firefox3 whilst loading and scrolling
> through the sites listed on http://wiki.mozilla.org/Mozilla2:Trender, we
> see:
> Allocator					Count	Bytes
> _cairo_pattern_create_copy			583303	80412256
> _cairo_skip_list_insert *			566032	12425880
> _cairo_freelist_alloc *				341702	2788704
> _cairo_gstate_clone				275247	99088920
> _cairo_array_grow_by				248526	1988208
> _cairo_region_get_boxes				197682	4867120
> _cairo_xlib_surface_create_internal		174801	68521992
> _cairo_bo_event_queue_init *			149475	90881712
> cairo_create					139520	126126080
> _cairo_pen_init_copy				112085	22154640
> * tessellator
> 
> I would like to push the _cairo_pattern_create_copy() down into the PDF
> backend -

Makes sense.


> I hesitate in case I've missed some subtlety in the
> interactions of the various paginated/meta/pdf layers that requires a
> reference rather than a copy. (And someone needs to review the use of
> cairo_pattern_reference within the Quartz backend.)

Well we can try to review if you send a patch ;).


> Whilst discussing
> the pattern copy, can we eliminate the copy entirely (other than when a
> snapshot is required) by tracking the pattern transform separately? If
> we can reuse the same pattern multiple times, then it becomes
> interesting to see what we can cache, or what resources we can minimise.

I wouldn't bother before one can describe a plan to gain from it.
Patterns are small objects anyway.  What's the gain?  And the issue here
is a general one, that various properties of an object have different
use patterns.  If you could break an object on each property you could
do more caching...  I have had this feeling about the scaled fonts
before.

For example, if metrics hinting is off, you will be always returning the
same metrics regardless of CTM.  It's quite natural to want to share the
cached metrics across different font sizes then.  But if metrics hinting
is on, you are back to different metrics per scaled font.  Kinda same
about glyph path when hinting is off.

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759



More information about the cairo mailing list