Skip to content

Speed up family matching

With the way typical font configurations look, matching the lists of families is the bottleneck for both FcFontMatch and FcFontSort. After installing the Noto fonts on my system, an innocent match pattern like "Cantarell 14" turns into a monster with a list of 300 family names after calling FcConfigSubstitute().

With this setup, every FcFontSort call takes 80-100 ms, which is entirely incompatible with using FcFontSort for anything interactive. And many font choosers render every font in itself, causing on average one FcFontSort call per font.

On my system, it takes more than 20 seconds to open the GTK font chooser dialog with fontconfig master, with frequent stalls when scrolling.

The major change in this MR special-cases font families and replaces the list walking for comparison with a hash table lookup. There's also a number of smaller speedups.

With this MR, the FcFontSort time goes to 6-8ms per call. Which is still not good enough for calling it dozens of times when scrolling, but a significant improvement, and the font chooser shows up in a little more than a second now.

Merge request reports