[cairo] [PATCH] scaled-font: optimize cairo_scaled_font_text_to_glyphs()

Behdad Esfahbod behdad at behdad.org
Wed Jun 9 11:38:38 PDT 2010


On 06/09/2010 12:20 PM, Dmitri Vorobiev wrote:
> +    uint32_t glyph_lut_unicode[GLYPH_LUT_SIZE];

Using something like CAIRO_STACK_ARRAY_LENGTH() is preferred.  However, we
need to make sure the number is a power of two here, so it's not straightforward.


> +    for (i = 0; i < ARRAY_LENGTH (glyph_lut_unicode); i++)
> +	glyph_lut_unicode[i] = ~0U;

Or you can initialize all to 0, and initialize [0] to non-zero.


> +    if (num_chars > 1)

I didn't notice that the glyph_lut was added to cairo.  I would have sugested
making the backend accesses and caches faster instead of adding yet another
cache on top...  After all, this cache is cleaned up across function calls!

Initializing 256 cache entries is a lot of overhead when in GUI's, the average
string lengths passed to cairo are really short, but longer than 1.
And I suggest making the cache smaller.  Much smaller.  According to
Wikipedia, the top 12 most frequent English letters comprise more than 80% of
the the total usage [1].  And I suggest extending the fast path to all short
strings (not only length 1).  So, what I suggest:

  - Either remove the lut cache or reduce it to 32 or 64 entries.

  - Bypass the cache codepath for strings shorter than 16.

  - As a special-case optimization in the non-cached case, if the current
letter is the same as the previous letter, skip the lookup and reuse the
result from last letter.


Perhaps I should dig into the git history to find what were the supporting
numbers when the cache was added in the first place.  Appreciate any pointers
(Chris added this I assume).

Cheers,
behdad

[1] http://en.wikipedia.org/wiki/Letter_frequency


> +	cairo_scaled_font_text_to_glyphs_internal_multiple (scaled_font,
> +					       x,
> +					       y,
> +					       utf8,
> +					       glyphs,
> +					       clusters,
> +					       num_chars,
> +					       &status);
> +    else
> +	cairo_scaled_font_text_to_glyphs_internal_single (scaled_font,
> +					       x,
> +					       y,
> +					       utf8,
> +					       glyphs,
> +					       clusters,
> +					       num_chars,
> +					       &status);
>


More information about the cairo mailing list