Bug 1784650

Summary: Fontconfig is slow, causing stuttering and freezing
Product: [Fedora] Fedora Reporter: bepvte+bugzilla
Component: fontconfigAssignee: Akira TAGOH <tagoh>
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: rawhideCC: ajax, caillon+fedoraproject, fonts-bugs, gnome-sig, i18n-bugs, john.j5live, mclasen, pnemade, rhughes, rstrode, sandmann, tagoh
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description bepvte+bugzilla 2019-12-17 22:17:00 UTC
Description of problem:
Fontconfig is much much slower than on other distros, and it stutters or freezes applications that use it.

Version-Release number of selected component (if applicable):

Name        : fontconfig
Version     : 2.13.92
Release     : 3.fc31
Architecture: x86_64

How reproducible:
I can reproduce this bug on a fresh Fedora 31 vm with the Xfce desktop and google-noto-sans-* fonts installed.

Steps to Reproduce:
1. dnf install google-noto-sans-*
2. run gedit on the attached example file

1. dnf install google-noto-sans-*
2. open firefox and browse to https://www.wikidata.org/wiki/Q52 (page with lots of languages)

Actual results:
It takes around 60 seconds for gedit to become responsive to scrolling and input. Mousepad is faster but still slow.
It takes firefox upwards of 5 minutes to get to first paint on a page with many fonts or languages, compared to a simpler page.

Expected results:
Gedit should load files with many fonts at a similar speed as other distros.
The page should load quickly, like on Debian and others.

Additional info:
I have tried to diagnose the source of this issue in many ways.

Running `perf trace` on what sysprof indicated was the most busy function (FcStrCmpIgnoreCaseAndDelims), shows that every name of every font family is being compared to every other name of every other font family. I do not know if this is a normal behaviour of fontconfig.

I have noticed the amount of calls to "FcStrCmpIgnoreCaseAndDelims" and program startup time both drop to a similar amount as Debian's when all of the "google-noto" configuration files in /etc/fonts/conf.d/ are deleted (These files are not present in Debian). However, this might not be the source of the problem:

In the Debian vm, with a copy of my computer's /etc/fonts/, including the google-noto files, (I took care to ensure that there would be no broken symlinks) and /usr/share/fonts, fontconfig does not stall any programs. The amount of calls to FcStrCmpIgnoreCaseAndDelims is also much lower as well.

This led me to believe that it was a difference caused by compiler flags but this does not seem to be the case. I tried to replace the optflags in the package, except for the rpmbuild required debug ones, and found no difference. I also checked to ensure that it was not caused by GCC version differences.

Debian results for mousepad:

1,845,449 calls to FcStrCmpIgnoreCaseAndDelims
Time: 5 seconds

Fedora results for mousepad:

11,658,380 calls to FcStrCmpIgnoreCaseAndDelims
Time: 23 seconds

Here is a link to a Firefox profiler result of the wikidata page, where in the flame graph you can see that Firefox is spending most of its time in fontconfig. You can also see "FirstNonBlankPaint" is at 50 seconds in the marker table.

TLDR: Fontconfig matching is slow with all google-noto fonts installed, unless you remove the noto config files. Using the same exact font directory and config directory (including the noto config files) on Debian does not cause the same problem.

Comment 1 bepvte+bugzilla 2020-04-29 15:38:06 UTC
https://bugs.chromium.org/p/chromium/issues/detail?id=1025356 Related chromium bug

Comment 2 Akira TAGOH 2020-10-20 05:55:34 UTC
Somewhat improved in upstream. but not yet making a release. hopefully we will see some improvements on this in f34.