[HarfBuzz] Caching of glyphmetrics and cmap data
behdad at behdad.org
Thu Sep 23 07:40:06 PDT 2010
Thanks for the effort. It's widely understood that FreeType's output is
supposed to be cached. Though I was hoping that the CMAP access was at least
Anyway, there are a few problems with caching these in harfbuzz proper:
1) I really really really want to keep the hb_face_t and hb_font_t objects
threadsafe. The easiest way to do so is to simply don't modify them beyond
construction. There are a couple places that we currently do touch them but I
plan to fix those.
2) Sometimes metrics can be cached on the face and linearly scaled for each
font, other times they are hinted to each font scale. So harfbuzz cannot by
its own do the best caching possible.
3) Almost all users of harfbuzz cache those things somewhere else anyway.
Pango has its own metrics and cmap caches. Cairo has its own metrics and cmap
caches. Fontconfig has its own cmap cache. Firefox has its own metrics and
cmap caches, etc etc.
So I think it's most reasonable to leave caching to the client. The only
problem is how to make hb-ft usable with that scheme. Here is one way to do it:
- Add a hb_font_steal_funcs() that will return the parameters passed to
hb_font_set_funcs() and unsets them in the font.
- Then you can create your font using hb-ft, then steal the
funcs/destroy/user_data from the font and wrap it into a caching wrapper.
Whether a caching wrapper should be part of harfbuzz is another question. I'm
not a huge fan, but can tolerate such a thing.
Another, perhaps better, option is to do the caching in hb-ft.c. I think I
like that even more.
On 09/23/10 08:52, Keith Stribley wrote:
> Hi Behdad,
> I've been comparing the rendering times taken by Harfbuzz-NG with
> different fonts and documents and as part of this experimented with
> caching for the freetype face and font. A lot of the time seems to be
> taken by calls to FreeType at the moment, specifically FT_Get_Char_Index
> and FT_Load_Glyph.
> I found that by caching both glyphmetric lookups (in the font) and the
> unicode to glyph mapping (in the face) I was able to improve the
> rendering performance by between 8 and 50 times depending on the font in
> large documents which don't require a lot of OT lookups.
> I've attached the patch that I was using. Perhaps it might be worth
> adding something like this as an option for clients for which memory is
> not at a high premium. The patch will probably need extending to benefit
> CJK and vertical metric fonts.
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
More information about the HarfBuzz