From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Kai Ma Newsgroups: gmane.emacs.bugs Subject: bug#71454: 30.0.50; Performance issues with font selection Date: Fri, 27 Sep 2024 09:51:06 +0200 Message-ID: <88D40848-CC43-4397-81EA-4BBB4B2EAC30@gmail.com> References: <22612F93-FC37-48E8-8137-E9FF6F5B3A0D@gmail.com> <86y13d8v3h.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.200.67\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_68710712-379A-497B-847C-5E2956D2CAB2" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2512"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Po Lu , Gerd =?UTF-8?Q?M=C3=B6llmann?= , Alan Third , 71454@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 27 09:52:54 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 1su5mX-0000V3-Ha for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 27 Sep 2024 09:52:53 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1su5mI-0000EH-KG; Fri, 27 Sep 2024 03:52:39 -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 1su5mE-0000E4-8c for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 03:52: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 1su5mD-0006ew-V4 for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 03:52:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:Date:Mime-Version:From:To:Subject; bh=/MnJoDOr7o0g+Mdi7NnSTuaPuK+abxxy5zxC/pohIZo=; b=stR8QORBm0FncJc88nYNvj2vG35gMgHRWlj8YDplBJO/YgAI32avTyQ419tC+ULJ00uJejTH1ugJrNkuJCFahegFH+bWWvvBAr9yerw+cbwnr4a3hcUXkFsGzSgxRbeeGEknPnIi3NA2zRbWgfY53ppNzWXq+9upvRH86TEV9dHl1cGqV3QI1Fk8Abf+Wc9t7Y30YCJuXoz9v+hXH5PdfQI6Sm8ChixRTujOsxccEt2djoGH8EWzoBDNPWjj5xTRrUS5Brfz/6stOQIcrZ/Lr3Vw2fNPzypUScsK1PUA1nMLx9hySYan3IAAPJjrgsPKuK4+ImXz/aCr3MDnozgaKw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1su5mg-0005lr-4w for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 03:53:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kai Ma Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Sep 2024 07:53: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.172742357422149 (code B ref 71454); Fri, 27 Sep 2024 07:53:02 +0000 Original-Received: (at 71454) by debbugs.gnu.org; 27 Sep 2024 07:52:54 +0000 Original-Received: from localhost ([127.0.0.1]:46871 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1su5mY-0005lB-61 for submit@debbugs.gnu.org; Fri, 27 Sep 2024 03:52:54 -0400 Original-Received: from mail-wm1-f68.google.com ([209.85.128.68]:56538) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1su5mW-0005ko-4S for 71454@debbugs.gnu.org; Fri, 27 Sep 2024 03:52:52 -0400 Original-Received: by mail-wm1-f68.google.com with SMTP id 5b1f17b1804b1-42cb60aff1eso17014075e9.0 for <71454@debbugs.gnu.org>; Fri, 27 Sep 2024 00:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727423478; x=1728028278; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=/MnJoDOr7o0g+Mdi7NnSTuaPuK+abxxy5zxC/pohIZo=; b=YrPEnt8+Cdn60XluaPQf9AkKQreoP7tiRgGTfRq6evELjmlkc5PiAQqK7oonzLDAoS xqHH9F0TMygtJlh2WbnApulO6+CskTSHk0+B6SVmtEqexB+2AKAkM5HpKfeuWTduv32q UIGN0bF04dNBE4q/rbe1nbpgJw8/zoGDYwacMUdutGR7cZGtZLLms9bQOPQXfa3Vl5Ib hA+gGeOuHnbhBaBf5UrIhKlm9XbXKsvpbsAKRJ+hxMxnptYhqs9of5aibzCAWOua/waK nJ7jH+a2tb+RQ8po4K1MR1D3Xu7WNswvn5AYfN+WD8MqkcOmPsjvhn/i+WKDhhTwGnD+ qJdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727423478; x=1728028278; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/MnJoDOr7o0g+Mdi7NnSTuaPuK+abxxy5zxC/pohIZo=; b=lQIJTufQiau9/+dj96p6OGHLNGjVSJktGol03EXvBFUYQGyfl0ndNy5b8HHZL7jD9V /voab+uog+jZ4QmwvAx/aXgVqbWBJ028AcR5UITv69yahC7nWdVOAkltVcs2SmzKVISJ u+j/tj82guxxooDLbVBotEgtPZ3kw1ksm87M0chwvXNdvPXW8JJPIpiqXtxKJCA9i1o3 4Y4W1Uu5HGJIqIGwPxWsBLu0IweUG2pPF4hS3ueG5MjZo/kNT6N3wle9DqYVRKU2nRNK Y99rwE1FcyMIkeOf3fxNuwRklt48QAGDtPMTMlGTj+T34DP12tp9qnGNXYRBf0MJUFJT v+sg== X-Forwarded-Encrypted: i=1; AJvYcCU4R7SX6RIDB+uVjyAbsQRvUxHyuOzIuGDbSwMor60UdPK9nbwM4+lHdiZw3wLomgWlj8DR2A==@debbugs.gnu.org X-Gm-Message-State: AOJu0YzO3qbOa3Z+w+hGambcPA+Oez7afRF1pBQipQ6AmuKz4OrzQhP1 2IKmhd/Xe/x5XWFfewzT/gZL3ouw/LDoYBU/5FRcxAO83bYaAThL X-Google-Smtp-Source: AGHT+IGBkLYXAbQfiq0m7CiPqwF1pXWiBdaW/fkRibzzU2OnLFiVgAeeosA2WokNSQa4KUzc/QnNDQ== X-Received: by 2002:a05:600c:4f14:b0:42c:ba83:3f0e with SMTP id 5b1f17b1804b1-42f5840dd9emr16681575e9.7.1727423477723; Fri, 27 Sep 2024 00:51:17 -0700 (PDT) Original-Received: from smtpclient.apple ([2a02:2454:8758:c800:a102:948e:6312:1c58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e969ffa22sm65892535e9.25.2024.09.27.00.51.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2024 00:51:17 -0700 (PDT) In-Reply-To: <86y13d8v3h.fsf@gnu.org> X-Mailer: Apple Mail (2.3826.200.67) 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:292498 Archived-At: --Apple-Mail=_68710712-379A-497B-847C-5E2956D2CAB2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Sep 27, 2024, at 08:32, Eli Zaretskii wrote: >=20 >>> I have currently (length (font-family-list)) =3D 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. >=20 > 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. > 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. >=20 > 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=E2=80=99m editing a file = with new emojis in Unicode 16 (released recently in September) and the = emojis are glyphless currently. I experience unbearable delays whenever = such glyphs are visible. Based on the profiling, my guess is that = CTFontDescriptorCreateMatchingFontDescriptors is doing a linear search = internally (it probably didn=E2=80=99t just pick the specified by the = font family?), so macfont_list is accidentally O(n^2). This (if true) = should explain why it=E2=80=99s so slow. --Apple-Mail=_68710712-379A-497B-847C-5E2956D2CAB2 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On = Sep 27, 2024, at 08:32, Eli Zaretskii <eliz@gnu.org> = wrote:

I have currently = (length (font-family-list)) =3D 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)?

Yes, if I = manually set the font, it becomes = instant.

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?

It would not eliminate the = problem though. I=E2=80=99m editing a file with new emojis in Unicode 16 = (released recently in September) and the emojis are glyphless currently. = I experience unbearable delays whenever such glyphs are = visible.

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

= --Apple-Mail=_68710712-379A-497B-847C-5E2956D2CAB2--