Subject: bug#44610: 27.1; Keyboard Macro Performance Problem

From: Robert Thorpe <[email-masked]>
Date: Fri, 13 Nov 2020 02:51:12 +0000

This bug report comes from a discussion on Emacs reddit.

Start with a blank buffer and create about ~300 lines of the string:

  ffffffffffffffffffff (pppppppppppppppppppp);

This will be turned into:

  'ffffffffffffffffffff':

That can be done using the following keyboard macro: M-m ' M-f ' : C-k
C-n

You can apply that to every line in the buffer using C-u 300 f4.

Now here's the strange bit.  In a fundamental-mode buffer this is
extremely fast, nearly instantaneous.  But, in a python-mode buffer it
takes 20 to 30 seconds.  If the mode is c-mode then it is also much
slower than fundamental-mode.  It will also exceed the variable binding
depth in some cases.  Oddly it is faster if you use forward-line instead
of C-n.

Here is the original thread:
https://www.reddit.com/r/emacs/comments/joeno5/anyway_to_speed_up_macros_in_emacs/

I understand it might not be worth fixing if it's a corner case.

BR,
Robert Thorpe

In GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22, cairo version 1.17.3)
 of 2020-08-28 built on juergen
Windowing system distributor 'The X.Org Foundation', version 11.0.12009000
System Description: Arch Linux

Recent messages:
Keyboard macro defined
Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %; q to quit; ? for help.
Mark set [2 times]
Saved text until "fffffffffffff (pppppppppppppppppppp);
  "
Mark set [2 times]
Defining kbd macro...
You can run the command ‘forward-line’ with M-x fo-lin RET
Keyboard macro defined
Can’t guess python-indent-offset, using defaults: 4

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --with-x-toolkit=gtk3 --with-xft --with-wide-int
 --with-modules --with-cairo --with-harfbuzz 'CFLAGS=-march=x86-64
 -mtune=generic -O2 -pipe -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY
INOTIFY ACL GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD JSON
PDUMPER LCMS2 GMP

Important settings:
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Python

Minor modes in effect:
  shell-dirtrack-mode: t
  dynamic-completion-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  global-visual-line-mode: t
  visual-line-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow mail-extr emacsbug sendmail eieio-opt cl-extra speedbar sb-image
ezimage dframe find-func thingatpt help-fns radix-tree help-mode python
tramp-sh tramp tramp-loaddefs trampver tramp-integration files-x
tramp-compat shell pcomplete parse-time iso8601 ls-lisp comint ring
ansi-color cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs dired-aux autorevert filenotify calc-alg
calc-ext calc-menu calc calc-loaddefs calc-macs view sort disp-table
tetris gamegrid rmailsum misearch multi-isearch noutline outline
easy-mmode shr-color color shr url-cookie url-domsuf url-util url-parse
auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs json map
url-vars svg xml dom browse-url qp rmailout rmailmm message rmc puny
dired-x dired dired-loaddefs format-spec rfc822 mml mml-sec
password-cache epa derived epg epg-config gnus-util time-date subr-x seq
byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies mm-encode
mailabbrev gmm-utils mailheader mail-parse rfc2231 rmail rmail-loaddefs
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils bookmark
easymenu text-property-search pp server completion avoid misc edmacro
kmacro cl-loaddefs cl-lib tooltip eldoc electric uniquify ediff-hook
vc-hooks lisp-float-type mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode elisp-mode lisp-mode prog-mode register page
tab-bar menu-bar rfn-eshadow isearch timer select scroll-bar mouse
jit-lock font-lock syntax facemenu font-core term/tty-colors frame
minibuffer 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
composite charscript charprop case-table epa-hook jka-cmpr-hook help
simple abbrev obarray 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
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 212016 51202)
 (symbols 48 17470 1)
 (strings 32 53646 2929)
 (string-bytes 1 1713027)
 (vectors 16 29359)
 (vector-slots 8 1024997 53850)
 (floats 8 262 286)
 (intervals 56 13457 0)
 (buffers 1000 44))