[cairo] [Patch] Surface cache

Jorn Baayen jorn at openedhand.com
Wed Jan 31 08:58:13 PST 2007


Hi,

On Wed, 2007-01-31 at 08:54 -0500, Behdad Esfahbod wrote:
> On Wed, 2007-01-31 at 15:43 +0200, Jorn Baayen wrote:
> > Hi,
> > 
> > On Mon, 2007-01-29 at 16:10 -0500, Behdad Esfahbod wrote:
> > > On Mon, 2007-01-29 at 15:05 -0500, Carl Worth wrote:
> > > > On Mon, 29 Jan 2007 18:56:49 +0200, Jorn Baayen wrote:
> > > > > Attached patch adds a simple 16-entry static cache to
> > > > > _cairo_pattern_acquire_surface_for_solid(). It still needs work,
> > > > however
> > > > 
> > > > Excellent! Thanks for providing this first step. What work is still
> > > > needed here? I know Behdad had expressed interest in doing this work,
> > > > so maybe he'll want to pickup your work and run with it. 
> > > 
> > > Excellent indeed.  And look how short the patch is!  The only things
> > > that immediately come to my mind are:
> > > 
> > >   - Needs locking around the cache.  Then you can use a static cursor
> > > too, for faster lookup (a cache of one there in itself).
> > > 
> > >   - With just backend comparison, does this work with two different X
> > > displays?  Guess not.
> > 
> > Attached patch should address these two, the second by adding an
> > is_similar method to cairo_surface_backend. xlib-surface implements this
> > and checks that the displays match. (implementations would need to be
> > written for other backends as well)
> 
> Thanks.  Looks really good.  "is_similar" is probably not the best name
> here, since it may return FALSE on a surface and another one created
> similar to it.  The similar surface may be a meta-surface (for SVG) or
> in image surface (under certain conditions for xlib).

Yea. What alternative namings can you think of?

> > >   - We have a faster random() implementation in cairo.  Lets use that.
> > 
> > You mean lfsr_random()? Isn't that very specialized? I see rand() being
> > used elsewhere, for example in _cairo_hash_table_random_entry().
> 
> No idea really.
> 
> 
> A small note:
> 
> 
> +    for (i = 0; i < cache_size; i++)
> +        if (_cairo_surface_is_similar (cache[i].surface, dst) &&
> +            _cairo_color_equal (&cache[i].color, &pattern->color))
> +            goto DONE;
> 
> I think surface_is_similar will be returning TRUE more often than
> color_equal here, so reordering the test will make it faster,
> theoretically.

Right. Done in attached version.

> Looks good enough to commit to me.  Xan, can you test?

I also attach the cairo-perf-diff report from a regular desktop machine.


Thanks,

Jorn

> 
> > Thanks,
> > 
> > Jorn
> 
-- 
OpenedHand Ltd.
http://o-hand.com/
-------------- next part --------------
Speedups
========
image-rgba  paint_similar_rgba_source-256    0.12 1.01% ->   0.09 0.53%:  1.41x speedup
?
image-rgba    paint_image_rgba_source-256    0.12 1.44% ->   0.09 0.22%:  1.38x speedup
?
image-rgb         fill_solid_rgb_over-64     0.32 2.30% ->   0.26 0.22%:  1.25x speedup
?
 xlib-rgb          long-lines-cropped-100    6.42 2.62% ->   5.31 0.98%:  1.21x speedup
?
image-rgb        paint_image_rgb_over-256    0.10 1.01% ->   0.09 0.37%:  1.18x speedup
?
image-rgb      paint_image_rgb_source-256    0.10 0.71% ->   0.09 0.53%:  1.17x speedup
?
image-rgb       pattern_create_radial-16     3.21 0.03% ->   2.75 0.21%:  1.17x speedup
?
image-rgb    paint_similar_rgb_source-256    0.10 0.35% ->   0.09 0.29%:  1.16x speedup
?
image-rgb      paint_similar_rgb_over-256    0.10 2.05% ->   0.09 0.34%:  1.16x speedup
?
 xlib-rgba         long-lines-cropped-100    7.09 0.48% ->   6.20 0.68%:  1.14x speedup
?
 xlib-rgba       text_solid_rgba_over-64     0.73 0.13% ->   0.65 0.14%:  1.12x speedup
?
 xlib-rgba        text_solid_rgb_over-64     0.73 1.08% ->   0.65 0.61%:  1.12x speedup
?
 xlib-rgba      text_solid_rgb_source-256   11.19 1.39% ->  10.09 1.77%:  1.11x speedup
?
 xlib-rgb       text_solid_rgb_source-64     1.47 0.35% ->   1.33 0.79%:  1.11x speedup
?
 xlib-rgba     text_solid_rgba_source-256   11.17 1.94% ->  10.07 1.74%:  1.11x speedup
?
image-rgb        paint_solid_rgb_over-512    0.80 0.33% ->   0.72 1.12%:  1.11x speedup
?
 xlib-rgb      text_solid_rgba_source-64     1.47 0.32% ->   1.33 0.71%:  1.10x speedup
?
 xlib-rgb      text_solid_rgba_source-256   11.32 2.63% ->  10.34 0.80%:  1.09x speedup
?
 xlib-rgb       text_solid_rgb_source-128    2.94 0.61% ->   2.69 1.91%:  1.09x speedup
?
image-rgb      paint_solid_rgb_source-512    0.79 0.80% ->   0.72 1.96%:  1.09x speedup
?
 xlib-rgba        text_solid_rgb_over-256    7.88 0.40% ->   7.21 2.01%:  1.09x speedup
?
 xlib-rgb        text_solid_rgba_over-256    8.13 2.82% ->   7.45 2.45%:  1.09x speedup
?
 xlib-rgba     text_solid_rgba_source-64     1.53 0.87% ->   1.40 0.54%:  1.09x speedup
?
 xlib-rgba       text_solid_rgba_over-256    7.86 0.87% ->   7.20 0.15%:  1.09x speedup
?
image-rgb     paint_solid_rgba_source-512    0.79 1.34% ->   0.72 1.65%:  1.09x speedup
?
 xlib-rgba      text_solid_rgb_source-64     1.53 0.53% ->   1.41 0.53%:  1.09x speedup
?
 xlib-rgb         text_solid_rgb_over-256    8.16 0.64% ->   7.50 1.15%:  1.09x speedup
?
 xlib-rgb      text_solid_rgba_source-128    2.95 0.43% ->   2.71 0.44%:  1.09x speedup
?
 xlib-rgb         text_solid_rgb_over-64     1.12 0.48% ->   1.03 0.71%:  1.09x speedup
?
 xlib-rgba        text_solid_rgb_over-128    2.32 0.78% ->   2.15 0.65%:  1.08x speedup
?
 xlib-rgb        text_solid_rgba_over-64     1.11 0.32% ->   1.03 0.38%:  1.08x speedup
?
image-rgba    fill_radial_rgba_source-256    5.70 0.57% ->   5.28 0.23%:  1.08x speedup
?
 xlib-rgba       text_solid_rgba_over-128    2.32 0.73% ->   2.15 0.46%:  1.08x speedup
?
image-rgba     fill_radial_rgb_source-256    5.69 0.64% ->   5.28 0.40%:  1.08x speedup
?
 xlib-rgb       text_solid_rgb_source-256   11.29 2.44% ->  10.48 0.74%:  1.08x speedup
?
 xlib-rgba      text_solid_rgb_source-128    3.40 0.43% ->   3.16 0.41%:  1.07x speedup
?
 xlib-rgb         text_solid_rgb_over-128    2.20 1.62% ->   2.05 0.67%:  1.07x speedup
?
 xlib-rgba   stroke_radial_rgb_source-256   43.45 0.39% ->  40.53 2.90%:  1.07x speedup
?
 xlib-rgba     text_solid_rgba_source-128    3.40 1.17% ->   3.17 0.46%:  1.07x speedup
?
 xlib-rgb        text_solid_rgba_over-128    2.20 0.16% ->   2.06 0.33%:  1.07x speedup
?
image-rgba     fill_radial_rgb_source-128    1.61 0.17% ->   1.51 0.21%:  1.07x speedup
?
image-rgba    fill_radial_rgba_source-128    1.61 0.24% ->   1.51 0.20%:  1.07x speedup
?
image-rgba      text_solid_rgb_source-64     1.03 1.32% ->   0.96 0.08%:  1.07x speedup
?
image-rgba     text_solid_rgba_source-64     1.03 0.46% ->   0.96 1.11%:  1.06x speedup
?
image-rgb          long-lines-cropped-100    6.22 0.08% ->   5.87 0.24%:  1.06x speedup

image-rgba         long-lines-cropped-100    6.22 0.33% ->   5.87 0.79%:  1.06x speedup

image-rgb              unaligned_clip-100    0.07 0.25% ->   0.07 0.51%:  1.06x speedup

image-rgb      text_solid_rgba_source-64     1.02 0.03% ->   0.96 0.02%:  1.06x speedup

image-rgb         text_solid_rgb_over-128    1.28 0.66% ->   1.22 0.05%:  1.05x speedup

image-rgb       text_solid_rgb_source-64     1.02 0.44% ->   0.97 0.04%:  1.05x speedup

image-rgb         text_solid_rgb_over-64     0.71 1.30% ->   0.68 0.04%:  1.05x speedup

image-rgb        text_solid_rgba_over-64     0.71 0.40% ->   0.68 1.39%:  1.05x speedup

 xlib-rgb            rectangle-stroke-100    0.36 0.29% ->   0.35 0.76%:  1.05x speedup

image-rgba     text_solid_rgba_source-256    8.83 0.29% ->   8.40 2.57%:  1.05x speedup

image-rgb        long-lines-uncropped-100    7.44 0.24% ->   7.08 0.19%:  1.05x speedup

Slowdowns
=========
image-rgba       paint_solid_rgb_over-512    0.74 2.79% ->   0.89 1.70%:  1.19x slowdown
?
image-rgba    paint_solid_rgba_source-512    0.75 0.75% ->   0.88 0.73%:  1.18x slowdown
?
image-rgba     paint_solid_rgb_source-512    0.74 0.77% ->   0.88 1.42%:  1.18x slowdown
?
 xlib-rgba   paint_radial_rgba_source-256   12.93 1.50% ->  14.41 0.94%:  1.11x slowdown
?
image-rgb       paint_radial_rgb_over-512   45.09 1.07% ->  49.56 0.24%:  1.10x slowdown
?
image-rgb     paint_radial_rgb_source-512   44.79 0.19% ->  48.93 0.94%:  1.09x slowdown
?
 xlib-rgba   paint_radial_rgba_source-512   54.11 0.75% ->  58.16 0.30%:  1.07x slowdown
?
 xlib-rgba     stroke_radial_rgb_over-128    3.88 0.38% ->   4.16 0.28%:  1.07x slowdown
?
 xlib-rgba    stroke_radial_rgba_over-128    3.89 0.95% ->   4.15 0.27%:  1.07x slowdown
?
image-rgb        fill_radial_rgb_over-128    1.35 0.26% ->   1.43 0.22%:  1.06x slowdown

image-rgba     paint_image_rgb_source-256    0.21 0.16% ->   0.22 0.31%:  1.06x slowdown

image-rgba       paint_image_rgb_over-256    0.21 0.05% ->   0.22 0.49%:  1.06x slowdown

image-rgba   paint_similar_rgb_source-256    0.21 0.01% ->   0.22 0.36%:  1.06x slowdown

image-rgba     paint_similar_rgb_over-256    0.21 0.36% ->   0.22 0.24%:  1.06x slowdown

image-rgb      stroke_radial_rgb_over-256    7.35 0.14% ->   7.75 2.68%:  1.05x slowdown

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cairo-surface-cache-2.patch
Type: text/x-patch
Size: 6867 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20070131/64c6ed71/cairo-surface-cache-2.bin


More information about the cairo mailing list