
The FreeType library for rendering text onto bitmaps that is widely used by a variety of applications has landed a set of three patches today providing an important performance improvement to address a significant inefficiency within the existing FreeType codebase.
Open-source developer Werner Lemberg has landed a set of three patches for speeding up the creation of the adjustment database’s reverse map. This is coming after it was uncovered that one of the functions can be extremely slow if a font is making use of a rich set of OpenType font features. The function could be called 66.9k times while loading the Arial TTF font and could increase FreeType’s startup time by a factor of ten.
Werner Lemberg explained in the first patch of the series now merged to FreeType Git:
“As it turns out, the original implementation using `hb_ot_shape_glyphs_closure` is extremely slow if a font has a rich set of OpenType features. For example, this function was called 66954 times while loading font `arial.ttf` version 7.00, increasing FreeType’s startup time by a factor of 10, which is unacceptable.
The new algorithm uses a completely different, more low-level approach, no longer working with OpenType features but with OpenType lookups. It relies on function `hb_ot_layout_lookup_get_glyph_alternates`, also replacing recursion with a simple loop. In total, this brings the additional startup time back to an acceptable range of a few percent.
A side effect of the new approach is that it catches more alternate forms: the old code didn’t properly handle script-specific features.”
All three patches for speeding up the creation of the adjustment database’s reverse map are merged as of today to FreeType Git for helping the load times for fonts making use of rich OpenType features.