[cairo] cairo-xlib patch to release glyph surfaces

Behdad Esfahbod behdad at behdad.org
Thu Oct 18 12:46:09 PDT 2007

On Thu, 2007-10-18 at 15:52 +0200, BJörn Lindqvist wrote:
> Hello!
> On 10/18/07, Behdad Esfahbod <behdad at behdad.org> wrote:
> > I'd like to commit the attached patch to cairo-xlib that makes it
> > release glyph surface after uploading it to the X surface iff the
> > surface didn't exist in the cache before we asked for it.
> >
> > The reasoning is that right now, applications render glyphs to images,
> > upload it to the X server, and keep a local copy in the cache.  The X
> > server works hard to reuse glyph renderings, by hashing glyph images and
> > reusing them.  So we are wasting memory in cairo apps that don't use the
> > glyph surface after uploading to the server, which is the case if you
> > don't use the glyph in an image surface.
> So the patch reduces memory consumption?

Yes, I believe that's what one gets from the patch :).

> Is there a way to measure the improvment?

'top' the project and see various process sizes?  I don't believe that
you can't think of any way to measure that.  Maybe you should have just
done that and reported your finding.

>  For example, if I have an app that takes 1800kb memory
> without and 1300kb with the patch applied.

Sure, I tested it and saw a 90kb shrinkage in a simple test case.  Don't
expect megs, we're just not using that much memory for glyph caches.
What the main purpose of the patch is however, is to allow us to
increase the cache size and yet in total use less memory than we used to
previously.  I propose increasing per-scaled-font cache size from 256 to
1024 after this patch.

> And thinking along the same
> lines.. Cairo already has correctness tests and performance tests,
> maybe tests that check memory consumption would also be useful?

Doesn't make much sense unless you have a build service reporting it on
a nightly basis.  Mozilla has one for example.  Would be interesting to
see the effect of this patch in ff3 builds.  hint hint...


"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