Subject: bug#26402: 25.2; Font rendering extremely slow on any non-default font

From: Gennady Uraltsev <[email-masked]>
Date: Sat, 8 Apr 2017 15:48:38 +0200

Font rendering in emacs is incredibly slow if any buffer-local change is
made i.e. unless using 'default.

I tried moving the cursor in a small (30 line) text file in emacs under
X. It works perfectly, also changing the default font size with

set-face-font or set-frame-font

works perfectly well. On the other hand, any buffer local change of font
makes everything extremely slow. These modifications include
(buffer-face-set 'fixed-pitch)

or

text-scale-adjust

The cursor gets redrawn around once every second making using emacs
impossible.

I am attaching the profiler logs for moving the cursor from the
beginning to the end of the 30 line buffer

Default run:
> - command-execute                                                 122  96%
>  - call-interactively                                             122  96%
>   - byte-code                                                      88  69%
>    - read-extended-command                                         88  69%
>     - completing-read                                              88  69%
>      - completing-read-default                                     88  69%
>       - read-from-minibuffer                                       25  19%
>        - redisplay_internal (C function)                            3   2%
>         - funcall                                                   3   2%
>          - #<compiled 0x26fa55>                                     3   2%
>           - gui-backend-selection-exists-p                          3   2%
>            - apply                                                  3   2%
>               #<compiled 0x49fcad>                                  3   2%
>        - command-execute                                            2   1%
>         - call-interactively                                        2   1%
>          - funcall-interactively                                    2   1%
>           - previous-line-or-history-element                        2   1%
>            - previous-history-element                               2   1%
>               goto-history-element                                  2   1%
>   - funcall-interactively                                          34  26%
>    - execute-extended-command                                      33  26%
>     - sit-for                                                      25  19%
>      - redisplay                                                   20  15%
>       - redisplay_internal (C function)                             4   3%
>        - funcall                                                    4   3%
>         - #<compiled 0x26fa55>                                      4   3%
>          - gui-backend-selection-exists-p                           4   3%
>           - apply                                                   4   3%
>              #<compiled 0x49fcad>                                   4   3%
>     - command-execute                                               8   6%
>      - call-interactively                                           8   6%
>       - funcall-interactively                                       8   6%
>        - profiler-report                                            8   6%
>         - profiler-report-cpu                                       8   6%
>            profiler-cpu-profile                                     8   6%
>    - next-line                                                      1   0%
>     - line-move                                                     1   0%
>      - line-move-partial                                            1   0%
>       - window-screen-lines                                         1   0%
>        - window-inside-pixel-edges                                  1   0%
>           window-edges                                              1   0%
> - ...                                                               4   3%
>    Automatic GC                                                     4   3%

Run after set-frame-font:

> - command-execute                                                 100  90%
>  - call-interactively                                             100  90%
>   - byte-code                                                      58  52%
>    - read-extended-command                                         58  52%
>     - completing-read                                              58  52%
>      + completing-read-default                                     58  52%
>   - funcall-interactively                                          42  37%
>    - execute-extended-command                                      36  32%
>     - sit-for                                                      24  21%
>      - redisplay                                                   17  15%
>       - redisplay_internal (C function)                             2   1%
>        - funcall                                                    2   1%
>         - #<compiled 0x26fa55>                                      2   1%
>          - gui-backend-selection-exists-p                           2   1%
>           - apply                                                   2   1%
>              #<compiled 0x49fcad>                                   2   1%
>     - command-execute                                              12  10%
>      - call-interactively                                          12  10%
>       - funcall-interactively                                      12  10%
>        - profiler-report                                           12  10%
>         - profiler-report-cpu                                      12  10%
>            profiler-cpu-profile                                    12  10%
>    - next-line                                                      6   5%
>     - line-move                                                     6   5%
>        line-move-visual                                             6   5%
> - ...                                                              10   9%
>    Automatic GC                                                    10   9%
> - timer-event-handler                                               1   0%
>  - apply                                                            1   0%
>     jit-lock-context-fontify                                        1   0%

BAD run after text-scale-adjust

> - command-execute                                                2024  99%
>  - call-interactively                                            2024  99%
>   - funcall-interactively                                        1999  98%
>    - next-line                                                   1965  96%
>     - line-move                                                  1965  96%
>      - line-move-partial                                         1433  70%
>       - default-line-height                                       730  35%
>          default-font-height                                      730  35%
>       - window-screen-lines                                       695  34%
>        - default-line-height                                      691  33%
>           default-font-height                                     691  33%
>        - window-inside-pixel-edges                                  4   0%
>           window-edges                                              4   0%
>       - window-inside-pixel-edges                                   8   0%
>        - window-edges                                               8   0%
>         - window-current-scroll-bars                                4   0%
>            frame-current-scroll-bars                                4   0%
>      - default-line-height                                        524  25%
>         default-font-height                                       524  25%
>        line-move-visual                                             4   0%
>      - window-inside-pixel-edges                                    4   0%
>       - window-edges                                                4   0%
>        - window-current-scroll-bars                                 4   0%
>           frame-current-scroll-bars                                 4   0%
>    - execute-extended-command                                      34   1%
>     - sit-for                                                      22   1%
>        redisplay                                                   16   0%
>     - command-execute                                              12   0%
>      - call-interactively                                          12   0%
>       - funcall-interactively                                      12   0%
>        - profiler-report                                           12   0%
>         - profiler-report-cpu                                      12   0%
>            profiler-cpu-profile                                    12   0%
>   - byte-code                                                      25   1%
>    - read-extended-command                                         25   1%
>     - completing-read                                              25   1%
>      - completing-read-default                                     25   1%
>         read-from-minibuffer                                       19   0%
> - ...                                                              11   0%
>    Automatic GC                                                    11   0%

BAD run after (buffer-set-face fixed-pitch)

> command-execute                                                1778  99%
>  - call-interactively                                            1778  99%
>   - funcall-interactively                                        1745  97%
>    - next-line                                                   1716  96%
>     - line-move                                                  1716  96%
>      - line-move-partial                                         1176  65%
>       - default-line-height                                       608  34%
>          default-font-height                                      608  34%
>       - window-screen-lines                                       568  31%
>        - default-line-height                                      568  31%
>           default-font-height                                     568  31%
>      - default-line-height                                        540  30%
>         default-font-height                                       540  30%
>    - execute-extended-command                                      29   1%
>     - sit-for                                                      15   0%
>        redisplay                                                   12   0%
>     - command-execute                                              14   0%
>      - call-interactively                                          14   0%
>       - funcall-interactively                                      14   0%
>        - profiler-report                                           10   0%
>         - profiler-report-cpu                                      10   0%
>            profiler-cpu-profile                                    10   0%
>          profiler-start                                             4   0%
>   - byte-code                                                      33   1%
>    - read-extended-command                                         33   1%
>     - completing-read                                              33   1%
>      - completing-read-default                                     33   1%
>         read-from-minibuffer                                       17   0%
> - ...                                                               8   0%
>    Automatic GC                                                     8   0%

In GNU Emacs 25.2.1 (x86_64-suse-linux-gnu, GTK+ Version 3.20.10)
 of 2017-03-27 built on lamb61
Windowing system distributor 'The X.Org Foundation', version 11.0.11803000
System Description:	openSUSE Leap 42.2

Configured using:
 'configure --with-pop --without-hesiod --with-kerberos --with-kerberos5
 --with-xim --with-wide-int --with-file-notification=inotify
 --with-modules --enable-autodepend --prefix=/usr
 --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share
 --localstatedir=/var --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --enable-locallisppath=/usr/share/emacs/25.2/site-lisp:/usr/share/emacs/site-lisp
 --with-x --with-sound --with-xpm --with-jpeg --with-tiff --with-gif
 --with-png --with-rsvg --with-dbus --with-xft --without-gpm
 --with-x-toolkit=gtk3 --with-xwidgets --x-includes=/usr/include
 --x-libraries=/usr/lib64 --with-libotf --with-m17n-flt
 --build=x86_64-suse-linux 'CFLAGS=-fmessage-length=0
 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector
 -funwind-tables -fasynchronous-unwind-tables -g -D_GNU_SOURCE
 -DGDK_DISABLE_DEPRECATION_WARNINGS -DGLIB_DISABLE_DEPRECATION_WARNINGS
 -pipe -Wno-pointer-sign -Wno-unused-variable -Wno-unused-label
 -Wno-unprototyped-calls -fno-optimize-sibling-calls -fno-PIE
 -DSYSTEM_PURESIZE_EXTRA=55000 -DSITELOAD_PURESIZE_EXTRA=10000 '
 LDFLAGS=-Wl,-O2'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND DBUS GCONF GSETTINGS NOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 MODULES XWIDGETS

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  value of $LC_MONETARY: de_DE.UTF-8
  value of $LC_NUMERIC: POSIX
  value of $LC_TIME: en_GB.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=local
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  buffer-face-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
Making completion list... [2 times]
delete-backward-char: Text is read-only
Making completion list... [3 times]
You can run the command ‘buffer-face-set’ with M-x bu-s RET
previous-line: Beginning of buffer [3 times]
CPU profiler stopped
CPU profiler started
next-line: End of buffer
Wrote /home/guraltsev/admin/bugs/emacs/font-slow/buffer-set-face-fixed-pitch
C-x <up> is undefined [2 times]

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message dired format-spec rfc822 mml
mml-sec password-cache epg epg-config gnus-util mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util help-fns help-mode mail-prsvr
mail-utils thingatpt profiler easymenu cl-loaddefs pcase cl-lib
face-remap time-date mule-util delsel lpr tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
dbusbind inotify dynamic-setting system-font-setting font-render-setting
xwidget-internal move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 121417 15744)
 (symbols 48 22660 0)
 (miscs 40 5039 157)
 (strings 32 23137 10436)
 (string-bytes 1 677307)
 (vectors 16 67484)
 (vector-slots 8 1659575 10120)
 (floats 8 184 184)
 (intervals 56 446 10)
 (buffers 976 24)
 (heap 1024 58366 8411))