Firefox freezing with 100% CPU usage for 30 seconds when launching Chromium

TL;DR: It's an issue with fontconfig before version 2.13. It can be fixed by upgrading the package to 2.13 or higher (though I couldn't find a suitable provider). Alternatively, examine all your fonts-related folders and config files in your home directory and test if removing any of them resolves your issue. For me, renaming ~/.fonts did the trick.


After learning about the bug reports https://bugzilla.mozilla.org/show_bug.cgi?id=1495900 and https://bugzilla.mozilla.org/show_bug.cgi?id=1411338 it becomes rather clear that the problem must be caused by fontconfig.

Somehow when Chromium starts, it triggers a change in the fonts database (???), which causes Firefox - if currently running - to re-scan the file system for fonts somehow, resulting in the CPU usage and temporary freeze.

Apparently updating the fontconfig package from version 2.11 to 2.13 (the version shipped e.g. in Ubuntu 18.10) should fix the issue, but I found no easy way to get that version on 16.04, without breaking dependencies of lots of other packages I have installed.

So as the issue is limited to my user account, I examined my user's local font configuration and folders. There's quite a mess of different font-related directories to be honest, including ~/.fonts, ~/.local/share/fonts, ~/.local/share-font-manager, ~/.config/font-manager, ~/.cache/font-manager, ~/.cache/fontconfig and a few more config files and application-specific font stuff.

I started by removing (renaming) the ~/.fonts folder, as it didn't seem to contain anything useful anyway, and a simple touch ~/.fonts/Library/ before that triggered the Firefox misbehaviour. After that folder was gone, so was the issue when launching Chromium. \o/


Background

It has been proposed this Firefox Bug 1492360: High CPU usage when open Firefox before chrome/chromium. That is a duplicate of Bug 1495900: Starting Chrome makes Firefox content processes hang for about two minutes, due to FontConfig font rescanning (FcInitReinitialize), is the culprit.

But I'm on Firefox too:

Firefox version.png

And when I open up Chrome:

Chrome version.png

I don't see any performance hit to CPUs.

It may be against your morals but perhaps you can try installing google-chrome-stable like I have. Then do the test again. If there is no CPU usage spike to 100% then a bug report could be filed between Chromium and Chrome.

I'm on Ubuntu 16.04.5 LTS. Although kernel is currently 4.14.78 LTS chain I don't think that has anything to do with it as I didn't notice CPU hits on previous kernels either.

The only time I see all CPU's at 100% is during update-initramfs.


fontconfig version

In the bug report it is revealed:

$ dpkg -l 'fontconfig*' | grep "^ii"
ii  fontconfig        2.12.6-0ubuntu2 amd64        generic font configuration library - support binaries
ii  fontconfig-config 2.12.6-0ubuntu2 all          generic font configuration library - configuration

In my non-buggy version (could be because of no local fonts though):

$ dpkg -l 'fontconfig*' | grep "^ii"
ii  fontconfig        2.11.94-0ubuntu1.1 amd64        generic font configuration library - support binaries
ii  fontconfig-config 2.11.94-0ubuntu1.1 all          generic font configuration library - configuration

I'm at 2.11.94 version earlier than bug report 2.12 version. In bug report upgrading to 2.13 is a recommended solution but OP mentioned in comments this isn't possible. As such 2.11.94 might be an option.