Subject: bug#29889: 27.0.50; Slow visual selection

From: Sujith <[email-masked]>
Date: Fri, 29 Dec 2017 09:22:22 +0530

Visual selection of text becomes very slow and hogs the
CPU in some cases.

For example, open the file lisp/progmodes/vhdl-mode.el in
the emacs codebase. And then, to reproduce this issue:

* Scroll patiently to the bottom using C-v.
  (this is essential, jumping to the bottom doesn't seem to bring
  up this issue).
* Set mark with C-SPC.
* Go to the beginning with M-<.
* Now move the cursor up and down.

The selection is jerky and CPU usage is very high.
I have tried this with emacs -Q and can see the issue. I am using
the master branch.

A profile report with this issue:

- #<compiled 0x41937d>                                           2499  53%
 - filter-buffer-substring                                       2499  53%
  - buffer-substring--filter                                     2499  53%
   - #<compiled 0x17002e5>                                       2499  53%
      apply                                                      2499  53%
- ...                                                            2102  44%
   Automatic GC                                                  2085  44%
 - minibuffer-complete                                             17   0%
  - completion-in-region                                           17   0%
   - completion--in-region                                         17   0%
    - #<compiled 0x10e5b45>                                        17   0%
     - apply                                                       17   0%
      - #<compiled 0x243ba7>                                       17   0%
       - completion--in-region-1                                   17   0%
        - completion--do-completion                                17   0%
         - completion-try-completion                               17   0%
          - completion--nth-completion                             17   0%
           - completion--some                                      17   0%
            - #<compiled 0x52cfb1>                                 17   0%
             - completion-basic-try-completion                     17   0%
              - try-completion                                     17   0%
               - #<compiled 0x24664f>                              17   0%
                  complete-with-action                             17   0%
+ command-execute                                                  87   1%
+ gui-set-selection                                                16   0%
+ redisplay_internal (C function)                                   3   0%

If any more information is needed, please let me know !

In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 2.24.31)
 of 2017-12-28 built on the-damned
Repository revision: b19df8ae78cdebe76512a70f76ec68677de41c11
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
Recent messages:
mwheel-scroll: Beginning of buffer [6 times]
scroll-down-command: Beginning of buffer
Undo!
uncompressing simple.el.gz...done
Note: file is write protected
uncompressing simple.el.gz...done
Note: file is write protected
scroll-down-command: Beginning of buffer [5 times]
Quit [2 times]
Making completion list...

Configured using:
 'configure --prefix=/usr --without-gconf --without-gsettings
 --without-selinux --without-gnutls --without-libsystemd
 --without-threads --without-dbus --with-x-toolkit=gtk2'

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND GPM NOTIFY ACL LIBXML2 FREETYPE
M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK2 X11 LCMS2

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

Major mode: Shell

Minor modes in effect:
  global-magit-file-mode: t
  diff-auto-refine-mode: t
  magit-auto-revert-mode: t
  global-git-commit-mode: t
  async-bytecomp-package-mode: t
  shell-dirtrack-mode: t
  display-time-mode: t
  iswitchb-mode: t
  savehist-mode: t
  override-global-mode: t
  save-place-mode: t
  cl-old-struct-compat-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  mouse-wheel-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
  column-number-mode: 1
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow flyspell ispell face-remap emacsbug cc-mode cc-fonts cc-guess
cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs help-fns
radix-tree find-func profiler dired-aux elec-pair mu4e-alert pcase ht s
alert log4e rx notifications dbus xml gntp magit-obsolete magit-blame
magit-stash magit-bisect magit-remote magit-commit magit-sequence
magit-notes magit-worktree magit-branch magit-collab ghub url-auth url
url-proxy url-privacy url-expand url-methods url-history url-cookie
url-domsuf url-util mailcap let-alist magit-files magit-refs
magit-status magit magit-repos magit-apply magit-wip magit-log
magit-diff smerge-mode diff-mode magit-core magit-autorevert autorevert
filenotify magit-process magit-margin magit-mode git-commit magit-git
magit-section magit-utils crm magit-popup log-edit pcvs-util add-log
with-editor cl-extra help-mode async-bytecomp async shell pcomplete dash
advice mu4e-contrib mu4e desktop frameset mu4e-speedbar speedbar
sb-image ezimage dframe mu4e-main mu4e-context mu4e-view cal-menu
calendar cal-loaddefs thingatpt browse-url comint ansi-color
mu4e-headers mu4e-compose mu4e-draft mu4e-actions ido rfc2368 smtpmail
sendmail mu4e-mark mu4e-message html2text mu4e-proc mu4e-utils doc-view
jka-compr image-mode mu4e-lists mu4e-vars message rmc puny format-spec
rfc822 mml mml-sec epa derived epg gnus-util rmail rmail-loaddefs
mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045 mm-util
ietf-drums mail-prsvr mailabbrev mail-utils gmm-utils mailheader hl-line
cl mu4e-meta battery time dired-x dired dired-loaddefs edmacro kmacro
xcscope ring zenburn-theme server iswitchb savehist bind-key easy-mmode
saveplace finder-inf info package easymenu epg-config url-handlers
url-parse auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache json map url-vars seq byte-opt gv bytecomp byte-compile
cconv cl-loaddefs cl-lib time-date mule-util 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 menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors 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 composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray 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 inotify lcms2 dynamic-setting font-render-setting move-toolbar
gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 385737 51929)
 (symbols 48 34919 1)
 (miscs 40 105 376)
 (strings 32 75656 5006)
 (string-bytes 1 2341110)
 (vectors 16 54734)
 (vector-slots 8 1167949 49516)
 (floats 8 149 357)
 (intervals 56 42540 1784)
 (buffers 992 18))