VOOZH about

URL: https://www.phoronix.com/news/FreeType-Slow-Loading-Arial-TTF

⇱ FreeType Fixes Inefficient Code Causing 10x Startup Time Hit When Loading Arial TTF Font - Phoronix


👁 Phoronix

FreeType Fixes Inefficient Code Causing 10x Startup Time Hit When Loading Arial TTF Font

Written by Michael Larabel in Desktop on 20 April 2025 at 06:33 AM EDT. 39 Comments
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.

👁 Arial TTF


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.

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.