Subject: Re: bug#71454: 30.0.50; Performance issues with font selection

From: Eli Zaretskii <[email-masked]>
Date: Fri, 27 Sep 2024 13:29:13 +0300

> From: Kai Ma <[email-masked]>
> Date: Fri, 27 Sep 2024 09:51:06 +0200
> Cc: Alan Third <[email-masked]>,
>  Po Lu <[email-masked]>,
>  Gerd Möllmann <[email-masked]>,
>  [email-masked]
> 
>  This part, about _any_ unusual characters causing a significant delay,
>  seems to imply that the default fontset is not set up correctly on
>  your system (or maybe in general on macOS), or perhaps that the way
>  the fontsets are used on macOS is very different from other systems.
>  For starters, are the fonts that Emacs selects for the characters you
>  used for testing different from the fonts defined by fontset-default
>  for those characters?  If so, what happens if you modify
>  fontset-default (using set-fontset-font) to specify for these
>  characters the same fonts as what Emacs selects with the default value
>  of fontset-default? does font selection become much faster (it
>  should)?
> 
> Yes, if I manually set the font, it becomes instant.

Thanks, so it means finding a font that matches the default font's
spec is indeed slow on your system.

I wonder if this is a general issue with macOS, or just with the
version and/or configuration you are running.

>  It could also be the matter of selecting the default face's font.  For
>  best results, it should be a font that covers many popular scripts, at
>  the very least Latin, Cyrillic, and Greek.  Judging by the "unusual"
>  characters you show, it sounds like Latin characters are not well
>  covered by your default face's font?  If so, perhaps choosing a font
>  with better coverage will make the situation better for you?
> 
> It would not eliminate the problem though.

I didn't mean that it will.  However, being able to display more
characters without delays is a Good Thing regardless.

> Based on the profiling, my guess is that CTFontDescriptorCreateMatchingFontDescriptors is doing a linear
> search internally (it probably didn’t just pick the specified by the font family?), so macfont_list is accidentally O
> (n^2).  This (if true) should explain why it’s so slow.

Yes, you said that in your original report.