Subject: Re: bug#32159: 26.1; inhibit-compacting-font-caches does not fix all fonts lagging issue

From: Eli Zaretskii <[email-masked]>
Date: Thu, 19 Jul 2018 16:41:52 +0300

> Date: Tue, 17 Jul 2018 18:05:36 +0300
> From: Eli Zaretskii <[email-masked]>
> Cc: [email-masked]
> 
> > On the other hand, browsers like Firefox, Chromium could display
> > every script fonts very fast without issue.
> 
> I don't know how the browsers look for fonts.  If someone does, maybe
> they can describe that, and we might then be able to learn something
> useful.

I've dug a little, and it looks like Firefox simply hard-codes an
explicit font name or a short list of explicit font names for every
"language" (what we call "script").  The defaults change whenever
Firefox developers decide that a better font is available on the
particular OS OOTB, or when a new version of the OS adds fonts.  To
see the defaults, type "about:config" into the address bar, and look
at the font.name-list.* variables.  The user can customize this (via
Options, hidden under "Fonts & Colors -> Advanced") by specifying a
single font for each script+style combination (where "style" is one of
Serif, Sans-Serif, and Monospaced).

Chrome seems to do something very similar, except that its defaults
are less sophisticated (many scripts don't have fonts defined and use
the global default font).

The advantage of this method is that it avoids font search in the
cases where by default there's only one font per script (slightly less
than 50% of the scripts in my version of Firefox), and makes the
search shorter when there are several candidate scripts in the
list.  The disadvantages are:

 . When the user installs a font that doesn't come with the OS OOTB,
   the only way to start using that font is to customize the defaults
   via Options.  Likewise, when a non-standard font is uninstalled
   that was previously customized to be used by Firefox.

 . The defaults explicitly name fonts installed on the OS, so for
   non-free systems, such as Windows, and maybe also for free systems,
   they name non-free fonts.  That is something we try very hard to
   avoid in our defaults, AFAIU.

Emacs defaults usually do not specify fonts explicitly (with a few
exceptions), but instead specify features that a font must have in
order to be considered for characters belonging to a script.  This
allows the user significant more flexibility, since which font will be
used is determined by the installed fonts, and does not require
customization after installed fonts change.  But the price is a
potentially longer search for a font, especially when a lot of fonts
are available on the system.

We could do something similar to what the browsers do, if we want, at
least on Free systems, but Someone™ would have to do the footwork of
looking at enough boxes and collecting free fonts that are available
OOTB there.  This could at least be an optional feature, for those who
don't intend changing their installed fonts too much, or not at all.
For non-free systems, the corresponding settings could be perhaps on
the wiki (and again, Someone™ should do the research and publish the
results).