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

From: Gerd Möllmann <[email-masked]>
Date: Sat, 28 Sep 2024 05:36:32 +0200

Eli Zaretskii <[email-masked]> writes:

>> From: Kai Ma <[email-masked]>
>> Date: Fri, 27 Sep 2024 00:42:04 +0200
>> 
>> I got back to this problem today and have some initial ideas.
>> 
>> I did some profiling and the profiler clearly shows that most CPU
>> time was in macfont_list and
>> CTFontDescriptorCreateMatchingFontDescriptors. (screenshot attached
>> below) So yes, it’s a Mac-only problem.
>> 
>> macfont_list will call CTFontDescriptorCreateMatchingFontDescriptors
>> for n times, where n is the number of installed fonts. It seems
>> CTFontDescriptorCreateMatchingFontDescriptors is very expensive, and
>> we should minimize the use of it.
>> 
>> I did a quick proof-of-concept patch (attached) that removes the
>> outer loop (utilizing CTFontDescriptorCreateMatchingFontDescriptors
>> itself to search for fonts). And now I no longer experience long
>> delays. It’s not complete as I haven’t adapted & incorporated
>> mac_font_create_preferred_family_for_attributes yet.
>> 
>> I don’t see noticeable font differences after the change on the
>> files I’m working on. I would like to gather some feedback from the
>> more experienced on whether this is a promising solution or not. If
>> it is, I will refine it into a formal patch.
>
> Thanks.  I'm adding a few people in the hope that they could comment
> on the patch, or maybe try it and provide feedback.

I haven't tried the patch because I can't reproduce the problem and I
don't use much beyond Latin-1 so I think chances are low that I'd see
anyting breaking with the patch.

But looking at the patch, which mostly removes stuff from macfont_list,
I wonder if/how that can be semeantically equalivalent to the existing
code.

Just saying, I'm definitely not an expert in this area.

Adding YAMAMOTO Mitsuharu <[email-masked]>, the original
author.