Subject: 29.0.50; Enabling pp-use-max-width dramatically slows down formatting of large sexps like org-persist--index

From: Michael Eliachevitch <[email-masked]>
Date: Fri, 21 Oct 2022 12:59:17 +0000

I set the new setting `pp-use-max-width' to t to fold the output of interactive commands  like `pp-eval-last-sexp'. However, I found out that this increased the time that kill-emacs took to run by 30 seconds. By profiling I found that this is because I use the latest org-version (9.5.5-gcb1359) on the main branch with persistent caching enabled and in `kill-emacs-hook' it then saves the `org-persist--index' to a file via `org-persist-write:index'. The index sexp can be quite large when one has many org files and when org uses pp on it that takes a long time.

What I wasn't aware when I customized pp-use-max-width is that it's used by other packages to format lisp code and this might slow down these operations quiet significantly, as I just wanted to set only for my custom pretty-printing purposes of usually small sexps.

My suggestion is to put a note into the emacs-news and the variable docstring that it can have significant performance penalties on large sexps. If the performance can be improved that would be also nice, but not sure if that's possible. I assume the authors are aware of the downsides, but it then should be documented well at least.

I attached a file with the value of my `org-persist--index` expression and a file with a benchmark where I run pp on it, which took me 25s when running it with emacs -Q. Until recently my org persist index was much longer, but I pruned it a bit back when I wasn't aware what exactly caused the slowdown.

I had reported this first on the org-mode mailing list at https://lists.gnu.org/archive/html/emacs-orgmode/2022-10/msg00734.html.

Best regards,
Michael Eliachevitch

--
In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.34, cairo version 1.17.6) of 2022-10-20 built on e490
Repository revision: f61db42fc580fb671016c77be942506d9081ac2c
Repository branch: master
System Description: Arch Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
 --with-modules --without-libotf --without-m17n-flt --without-gconf
 --enable-link-time-optimization --with-native-compilation
 --with-xinput2 --with-pgtk --without-xaw3d --with-sound=alsa
 --with-xwidgets --without-gpm --without-compress-install
 '--program-transform-name=s/\([ec]tags\)/\1.emacs/'
 'CFLAGS=-march=native -mtune=generic -O3 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection'
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PGTK
PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS WEBP XIM
XWIDGETS GTK3 ZLIB

Important settings:
  value of $XMODIFIERS: @im=fcitx
  locale-coding-system: nil

Major mode: ELisp/d

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-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
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils time-date edebug debug
backtrace find-func benchmark pp vc-git diff-mode easy-mmode
vc-dispatcher cl-loaddefs comp comp-cstr warnings icons subr-x rx cl-seq
cl-macs gv cl-extra help-mode bytecomp byte-compile cconv cl-lib rmc
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/pgtk-win pgtk-win term/common-win
pgtk-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list
replace newcomment text-mode lisp-mode prog-mode register page tab-bar
menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse
jit-lock font-lock syntax font-core term/tty-colors frame minibuffer
nadvice seq simple cl-generic indonesian philippine 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 composite emoji-zwj charscript charprop
case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads xwidget-internal dbusbind inotify dynamic-setting
system-font-setting font-render-setting cairo gtk pgtk lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 92875 7823)
 (symbols 48 8353 1)
 (strings 32 23567 2442)
 (string-bytes 1 712274)
 (vectors 16 17653)
 (vector-slots 8 356365 12834)
 (floats 8 30 53)
 (intervals 56 434 3)
 (buffers 1000 15))