From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#71454: 30.0.50; Performance issues with font selection Date: Fri, 27 Sep 2024 09:32:50 +0300 Message-ID: <86y13d8v3h.fsf@gnu.org> References: <22612F93-FC37-48E8-8137-E9FF6F5B3A0D@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19345"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71454@debbugs.gnu.org To: Kai Ma , Alan Third , Po Lu , Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 27 08:33:52 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1su4Y3-0004qk-Jc for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 27 Sep 2024 08:33:52 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1su4Xo-0002pS-51; Fri, 27 Sep 2024 02:33:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1su4Xm-0002hw-9S for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 02:33:34 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1su4Xm-0005uT-0v for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 02:33:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-version:References:In-Reply-To:From:Date:To:Subject; bh=5/SSQ0d3tazUw2YULWgNncwtdVflcPtk1gxwXqRZfbo=; b=Hu5Oj/G9IT/+npO9eZGnJ8OTjE4I7eeIs83+IiZD4V1Z17eiaIbvZJlhJ95uXC5BM6rfax9D5fHh1ZCK32IwUMudGAE2FSSIhBHSdQQspt2YyeyuuQruY/Oyb0yFMxKCd0KPIs39JhbnhTr8SzYk/alGXCXJVVkhnLxEDwHImPpYlGS7FvhQhduWkk4UKa9/CZ4PLieZFkjwBxQDBbL6KoedK096iQfNZ7xlhlnuyzTDQhW0+0eneqGgnQG+Jk3TnIfWXU6cD1JNn1cK6ApOPzmQVX+jBPI0cV9LpsnhJ/X+oCPmjNwdvP8uHflYWWZ/h99m2JJz8IrpL+DXoTanMw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1su4YE-0000xa-41 for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 02:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Sep 2024 06:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71454 X-GNU-PR-Package: emacs Original-Received: via spool by 71454-submit@debbugs.gnu.org id=B71454.17274188143649 (code B ref 71454); Fri, 27 Sep 2024 06:34:02 +0000 Original-Received: (at 71454) by debbugs.gnu.org; 27 Sep 2024 06:33:34 +0000 Original-Received: from localhost ([127.0.0.1]:45303 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1su4Xm-0000wn-Ey for submit@debbugs.gnu.org; Fri, 27 Sep 2024 02:33:34 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:39618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1su4Xk-0000wU-S1 for 71454@debbugs.gnu.org; Fri, 27 Sep 2024 02:33:33 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1su4XB-0005qA-17; Fri, 27 Sep 2024 02:32:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=5/SSQ0d3tazUw2YULWgNncwtdVflcPtk1gxwXqRZfbo=; b=SviXgNBaGG6rimipO9Ob KnsajWA/GLY8V0bemGebxS231Tpz4f2f1uWZoQY3hfG4HEPaTI37g+DqMXEa4Er1xd6UMFqm0Inw7 9UQkGVaq4XWwplZeZ3GHTMf5d89q/sF5oA0D6UADfcTExp3RO2AnpGdQLv36EqUmUL4Fv3O7PcxOw MutVlEa+Bbpab+lMOWM9Nt3/liAvagQm+EBlN9Q8HXfYSJzMEZIDlYns2A3+UkIl4yBsimHILwGxL CMvZDeLVwqveAJomfeUgtZ2er8QCltBe0MiDfnyaGTY+AiA8KvSwhpGD5VkHYXMEcuK5D6N1Qk8ID /EulOLILMs0f8w==; In-Reply-To: <22612F93-FC37-48E8-8137-E9FF6F5B3A0D@gmail.com> (message from Kai Ma on Fri, 27 Sep 2024 00:42:04 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:292493 Archived-At: > From: Kai Ma > 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 have currently (length (font-family-list)) = 582 font families > > installed. And whenever I input some ununsual characters, Emacs will > > freeze for seconds until I am able to do anything else. Worse, the > > freeze delay for each character will add up. And whenver the face > > changes (including hl-line-mode), or I switched to another buffer for > > some time, there will be a delay again. 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)? If specifying the precise font in the fontset doesn't speed up font selection, then something is very wrong with how fontsets are used on macOS. Emacs comes with the default value of fontset-default that is already configured for many characters, and the ones you show should be included. So I'm puzzled why you experience such long delays when some of those characters are used. 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?