all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ralf Jung <post@ralfj.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 21028@debbugs.gnu.org
Subject: bug#21028: Slow font rendering in emacs
Date: Tue, 14 Mar 2017 19:41:15 +0100	[thread overview]
Message-ID: <4000d0c9-493c-3e14-f070-f35555e240dd@ralfj.de> (raw)
In-Reply-To: <83innbc122.fsf@gnu.org>

Hi,

>> Here's the setup which makes things behave badly:
>>
>> (dolist (ft (fontset-list))
>>   ; Main font
>>   (set-fontset-font ft 'unicode (font-spec :name "Monospace" :size 11.0))
>>   ; Fallback font
>>   (set-fontset-font ft 'unicode (font-spec :name "DejaVu Sans Mono"
>> :size 11.0) nil 'append)
>> )
>>
>> And here's the one I use instead, which behaves much better:
>>
>> (dolist (ft (fontset-list))
>>   ; Main font
>>   (set-fontset-font ft 'unicode (font-spec :name "Monospace" :size 11.0))
>>   ; Fallback font
>>   (set-fontset-font ft nil (font-spec :name "DejaVu Sans Mono" :size 11.0))
>> )
>>
>> (For the record, my "Monospace" font is "Fira Sans Mono".)
> 
> See, this setup makes very little sense.  It sets up no less than 2
> monospaced fonts for the entire range of Unicode codepoints, when both
> of these fonts support only Latin, Greek, and Cyrillic blocks.

Well, maybe it makes little sense to you -- however, this requires
expert knowledge about unicode blocks.  I don't have that knowledge, and
I think it is a bug if configuring a straight-forward fallback chain of
fonts requires such knowledge.  *Not* knowing these details about which
font supports what, I'd say my setup makes a lot of sense.
Well, actually, the following would make even more sense:

(set-fontset-font "fontset-default" 'unicode (font-spec :name
"Monospace" :size 11.0))
(set-fontset-font "fontset-default" 'unicode (font-spec :name "DejaVu
Sans Mono" :size 11.0) nil 'append)

I think back then I didn't yet know about 'append, so I used the nil
range for the fallback font (the documentation even said something
related to fallback for the nil range) and then I had to do this for all
fontsets for it to have any effect...
Anyway, I just tried the above, and the result is that things are just
as slow as with my previous "bad" setup.  And this time, I honestly
can't think of a clearer / more sensible way to tell emacs that these
are the fonts I (mainly) want to use for unicode characters.

>  What's
> more, this is done in all the fontsets, so Emacs will waste many
> cycles on futile search through these fonts, multiple times!

So the slowdown happens even if I do this in just one fontset.
How can searching two fonts take so much time?  95% of the characters in
my document are present in Fira Sans, and only about 0.1% of the
characters (I am guessing here, I suspect actually it's even less) are
present in neither DejaVu nor Fira Sans.  So having these two fonts
first should result in very quick, successful lookups.

> Try this instead:
> 
>   (set-fontset-font "fontset-default" 'greek
>                     (font-spec :name "DejaVu Sans Mono"
> 		    :size 11.0 :registry "iso10646-1") nil 'prepend)
>   (set-fontset-font "fontset-default" 'cyrillic
>                     (font-spec :name "DejaVu Sans Mono"
> 		    :size 11.0 :registry "iso10646-1") nil 'prepend)
>   (set-fontset-font "fontset-default" 'latin
>                     (font-spec :name "DejaVu Sans Mono"
> 		    :size 11.0 :registry "iso10646-1") nil 'prepend)
>   (set-fontset-font "fontset-default" 'greek
>                     (font-spec :name "Monospace"
> 		    :size 11.0 :registry "iso10646-1") nil 'prepend)
>   (set-fontset-font "fontset-default" 'cyrillic
>                     (font-spec :name "Monospace"
> 		    :size 11.0 :registry "iso10646-1") nil 'prepend)
>   (set-fontset-font "fontset-default" 'latin
>                     (font-spec :name "Monospace"
> 		    :size 11.0 :registry "iso10646-1") nil 'prepend)
>   (set-fontset-font t nil (font-spec :name "Symbola"
>                                      :size 11.0 :registry "iso10646-1")
>                           nil 'append)

With this configuration, emacs picks STIX to render ∃.  It also picks
"DejaVu Math TeX Gyre" for ↦.  This breaks the monospace grid.  Both of
these characters are supported by DejaVu Sans Mono.

You say these fonts support only Latin, Cyrillic and Greek -- but for
example Fira Sans Mono supports → and … and ↑, and DejaVu Mono supports
∃ and ↦ and ▷.  Are these all in one of these ranges?

> (I'd also drop the :size part, but maybe you have a good reason for
> that.)

Well, I want to use a smaller font size than the default.  If I use the
"normal" way to do that through the "Set Default Font" UI, the fonts of
most characters changed, but when some fallback font was picked, it used
the default size again so the characters were way too big.  I fixed this
by adding the size to every single fontspec.
So, no, no good reason. I was just desperate.

> I suggest to look at fontset.el in the Emacs sources for inspiration
> on how to set up the fontset correctly.

Frankly, I do not plan to figure out which of my fonts support which
unicode block, nor do I want to spend hours manually selecting the right
font for each individual character.  I believe that this is something
the machine can figure out for me.  With more than two billion
instructions per second, it should be capable of querying two (!) fonts
for every one of the maybe 1000 characters it has to display at any
given time.

> Or ask on emacs-devel.

Well, yes, I admit I should/could have done that.  After spending
something like 2 or 3 hours on this issue, I was frustrated and didn't
find the motivation any more to describe in detail what I tried and what
went wrong.

> If the manual configuration forces Emacs to unnecessarily search fonts
> for characters that aren't there, then it could get unreasonably slow.
> We are giving the users here enough rope to hang themselves, in the
> hope that they won't try doing that too hard...

I had no intention to hang myself, but may have accidentally strangled
myself in the 25 ropes that emacs gave me to configure fonts -- where
all I wanted was for things to look just like they look in any other
editor...

Kind regards,
Ralf





  reply	other threads:[~2017-03-14 18:41 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-10 10:34 bug#21028: Performance regression in revision af1a69f4d17a482c359d98c00ef86fac835b5fac (Apr 2014) Clément Pit--Claudel
2015-07-10 12:30 ` Eli Zaretskii
2015-07-10 16:02   ` Clément Pit--Claudel
2015-07-10 12:41 ` Eli Zaretskii
2015-07-10 16:55   ` Clément Pit--Claudel
2015-07-15 12:32     ` Dmitry Antipov
2015-07-18 10:24       ` Clément Pit--Claudel
2015-07-18 11:16         ` Clément Pit--Claudel
2015-07-18 11:26           ` Eli Zaretskii
2015-07-18 20:08             ` Clément Pit--Claudel
2016-03-03  6:12       ` Clément Pit--Claudel
2016-03-03  6:42         ` Clément Pit--Claudel
2016-03-03  7:08           ` Clément Pit--Claudel
2016-03-03  7:33             ` Clément Pit--Claudel
2016-03-03 17:10               ` Glenn Morris
2016-03-03 17:28                 ` Clément Pit--Claudel
2016-03-03 20:27               ` Eli Zaretskii
2016-07-20 21:26                 ` Clément Pit--Claudel
2016-07-21 14:21                   ` Eli Zaretskii
2016-07-21 14:33                     ` Clément Pit--Claudel
2016-07-23 20:50                     ` Clément Pit--Claudel
2016-10-04 22:17                       ` Clément Pit--Claudel
2016-10-26 17:15                         ` Clément Pit--Claudel
2016-10-27 14:38                           ` Eli Zaretskii
2016-10-27 15:29                             ` Clément Pit--Claudel
2016-10-27 15:55                               ` Eli Zaretskii
2016-10-28 14:23                                 ` Clément Pit--Claudel
2016-10-28 14:33                                   ` Eli Zaretskii
2016-11-18  8:55                                     ` Eli Zaretskii
2016-12-18 17:33                                     ` Clément Pit--Claudel
2016-12-18 17:37                                       ` Eli Zaretskii
2016-12-18 18:04                                         ` Clément Pit--Claudel
2016-12-18 19:52                                           ` Eli Zaretskii
2016-12-18 20:44                                             ` Clément Pit--Claudel
2016-12-19 15:50                                               ` Eli Zaretskii
2016-12-19 16:25                                                 ` Clément Pit--Claudel
2016-12-19 16:39                                                   ` Eli Zaretskii
2016-12-19 16:55                                                     ` Clément Pit--Claudel
2016-12-19 16:58                                                       ` Eli Zaretskii
2016-12-19 17:13                                                         ` Clément Pit--Claudel
2016-12-22 16:25                                                           ` Eli Zaretskii
2016-12-22 16:49                                                             ` Clément Pit--Claudel
2016-12-22 18:04                                                               ` Eli Zaretskii
2016-12-22 19:08                                                                 ` Clément Pit--Claudel
2017-02-10  4:45                                                                   ` Clément Pit--Claudel
2017-03-12 11:38                                                                     ` Clément Pit--Claudel
2017-03-12 15:49                                                                       ` Eli Zaretskii
2017-03-12 17:24                                                                         ` Clément Pit--Claudel
2017-03-12 17:48                                                                           ` Eli Zaretskii
2017-03-12 19:19                                                                             ` Clément Pit--Claudel
2017-03-13 15:46                                                                               ` Eli Zaretskii
2017-03-13 16:36                                                                                 ` Clément Pit--Claudel
2017-03-13 17:22                                                                                   ` Eli Zaretskii
2017-03-13 19:04                                                                                     ` Clément Pit--Claudel
2017-03-13 20:53                                                                                       ` Eli Zaretskii
2017-03-14 19:45                                                                                         ` Clément Pit--Claudel
2017-03-15 15:37                                                                                           ` Eli Zaretskii
2017-03-14 15:45                                                                                       ` Eli Zaretskii
2017-03-14 19:35                                                                                         ` Clément Pit--Claudel
2017-03-15 15:36                                                                                           ` Eli Zaretskii
2017-03-15 20:46                                                                                             ` Clément Pit--Claudel
2017-03-16 15:27                                                                                               ` Eli Zaretskii
2017-03-16 21:23                                                                                                 ` Clément Pit--Claudel
2017-03-17  8:15                                                                                                   ` Eli Zaretskii
2017-04-16  7:48                                                                                                 ` Eli Zaretskii
2017-04-16 15:28                                                                                                   ` Clément Pit--Claudel
2016-12-19 17:00                                                     ` Clément Pit--Claudel
2015-07-10 15:42 ` Glenn Morris
2016-03-03  6:37   ` Clément Pit--Claudel
2016-10-04 18:56 ` Jason Gross
2017-03-13 15:54 ` bug#21028: Slow font rendering in emacs Ralf Jung
2017-03-13 17:05   ` Eli Zaretskii
2017-03-13 18:12     ` Ralf Jung
2017-03-13 20:39       ` Eli Zaretskii
2017-03-14 15:57         ` Ralf Jung
2017-03-14 17:11           ` Eli Zaretskii
2017-03-14 18:50             ` Ralf Jung
2017-03-14 19:16               ` Eli Zaretskii
2017-03-14 19:17             ` Ralf Jung
2017-03-14 20:49             ` John Mastro
2017-03-15 15:40               ` Eli Zaretskii
2017-03-14 15:47   ` Eli Zaretskii
2017-03-14 18:41     ` Ralf Jung [this message]
2017-03-14 19:16       ` Eli Zaretskii
2017-03-14 19:39         ` Ralf Jung
2017-03-14 19:45           ` Ralf Jung
2017-03-15 15:36           ` Eli Zaretskii
2017-04-22  8:54             ` Ralf Jung
2017-04-22 13:40               ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4000d0c9-493c-3e14-f070-f35555e240dd@ralfj.de \
    --to=post@ralfj.de \
    --cc=21028@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.