bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#21028: Slow font rendering in emacs


From: Eli Zaretskii
Subject: bug#21028: Slow font rendering in emacs
Date: Tue, 14 Mar 2017 21:16:05 +0200

> Cc: 21028@debbugs.gnu.org
> From: Ralf Jung <post@ralfj.de>
> Date: Tue, 14 Mar 2017 19:41:15 +0100
> 
> 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.

I don't think there's a bug here.  Fontsets are complex and delicate
means of customizing how Emacs looks for fonts, so using them does
require expert knowledge.  Emacs believes the specifications in the
fontset blindly, so a misconfigured fontset could cause a real
slowdown.

The way we try to solve these issues is by having Emacs DTRT by
default, at least on most modern platforms.  Emacs 25.1 made a
significant step forward in this regard.  If that's still not enough,
then the way to improve that is to describe your needs and installed
fonts, and ask for a fontset that would exist in Emacs by default,
which will do what you (and presumably others) would want.

IOW, the way to fix this is to augment the existing default fonts or
maybe create an additional ready-to-be-used fontset that users could
simply tell Emacs to use, without any tinkering.

> *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)

Not in general.  Maybe if you only need a small subset of Unicode the
above is good enough.  But with today's increasing use of special
characters and symbols, and also emoji, more and more Unicode blocks
need to be supported by the fonts you set up, and the above simply
won't cut it.

> 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.

The more sensible way is to specify explicit ranges of codepoints
where you want certain fonts, and leave the rest to the defaults.

> How can searching two fonts take so much time?

They are searched many times, including their variants.

> 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.

These lookups are done many times, and Emacs also looks in other fonts
on your system, because the above fontset specification doesn't remove
all the other fonts that are in the fontset.  IOW, your spec is too
general, and thus doesn't allow Emacs to efficiently zero in on the
font you want in each case.

> > 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.

Well, I don't really know the details of what you want to achieve, so
the above might need some tweaking, like using explicit ranges of
codepoints.

> 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?

No.  But the rest of the blocks are covered only very partially, so my
suggestion would be to find a single monospaced font that covers the
other characters (symbols and punctuation), and use only it, instead
of having some of them displayed by one font and the rest by another
(and probably quite a few not covered by any of them).

The default fontset tries to achieve this by using Symbola, but if you
want a monospaced font in those areas as well, you will have to find a
suitable font.  You can then set up your fontset like we do with
Symbola in fontset.el (in the Emacs 25 sources).

> > 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.

The machine cannot possibly know your desires, or which fonts you do
and don't like.  It has a fixed set of criteria, and it applies them
in some predefined order.  When the results are not to your liking,
you need to make amends, and the recommended way of doing so is by
small changes that correct only the specific cases which don't look
good by default.  By contrast, your setup affects the entire Unicode
range, and this runs a greater risk of causing trouble.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]