Subject: 26.0.60; Rendering lag spikes caused by double-buffering on Linux

From: Bryan Gilbert <[email-masked]>
Date: Tue, 03 Oct 2017 23:10:16 -0400

Hi,

I've been using the Emacs 26 release branch and I've noticed a
significant amount of rendering lag spikes. When this occurs the UI
completely locks up in Emacs (and the desktop) for short periods of
time. Better than an explanation I have two very short screencasts
included below the display the behavior.

I've been able to reproduce the problem with 100% reliability using the
`counsel-rg` command from ivy/swiper (full details to reproduce below).
I've also used git bisect to narrow down the exact commit these lag
spikes were introduced as this commit:

https://github.com/emacs-mirror/emacs/commit/c29071587c64efb30792bd72248d3c791abd9337

I was able to verify that reverting to the previous commit before
double-buffering was added completely removed the problem. I've made two
short screencasts, one before the double-buffer commit and the other
after.

Before: http://drop.bryan.sh/YtUzfcSRp7.mp4
After: http://drop.bryan.sh/UyRpSc4NyQ.mp4

The behavior is unaffected by the glxgears program I have running in
both screencasts, I just used it as a method to show when the screen is
locking up. In the second screencast when it looks like the screen is
completely locked up, I am just pressing the 'e' and 'backspace' in
alternation once every second.

Two minor precursors to running the steps to reproduce are that one
would need to be running Linux and have 'rg' installed. 

Steps to Reproduce using emacs -Q:

1. Add the melpa archive

    (require 'package)
    (add-to-list 'package-archives
                '("melpa" . "http://melpa.org/packages/"))

2. Install Counsel:

    (package-refresh-contents)
    (package-install) ;; counsel

3. Enable Ivy:

    (ivy-mode 1)

4. Change counsel-rg minimum query length from 3 characters to 1 character:

    (defun ivy-counsel-ag-function (string base-cmd extra-ag-args)
      (when (null extra-ag-args)
          (setq extra-ag-args ""))
      (if (< (length string) 1)  ;; #1
          (counsel-more-chars 1)
          (let ((default-directory counsel--git-dir)
              (regex (counsel-unquote-regex-parens
                      (setq ivy--old-re
                              (ivy--regex
                              (counsel-unquote-regex-parens string)))))) ;; #2
          (let* ((args-end (string-match " -- " extra-ag-args))
                  (file (if args-end
                          (substring-no-properties extra-ag-args (+ args-end 3))
                          ""))
                  (extra-ag-args (if args-end
                                      (substring-no-properties extra-ag-args 0 args-end)
                                  extra-ag-args))
                  (ag-cmd (format base-cmd
                                  (concat extra-ag-args
                                          " -- "
                                          (shell-quote-argument regex)
                                          file))))
              (if (file-remote-p default-directory)
                  (split-string (shell-command-to-string ag-cmd) "\n" t)
              (counsel--async-command ag-cmd)
              nil)))))

    (advice-add #'counsel-ag-function :override #'+ivy*counsel-ag-function)

5. Run 'counsel-rg', begin typing, and notice large lag spikes

    (counsel-rg)

Step number 3 is a bit of a messy step, however by lowering the minimum
query size from 3 characters to 1 character makes the rendering lag spikes
painfully obvious.

Thanks!

=========================================================================

In GNU Emacs 26.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.21)
 of 2017-09-28 built on borealis
Repository revision: 88a0dd71f10ffb63fba08c062e948551c3e876c2
Windowing system distributor 'The X.Org Foundation', version 11.0.11903000
System Description:	Arch Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
 --with-sound=alsa --with-xft --with-modules --with-x-toolkit=gtk3
 --without-gconf --without-gsettings --without-gpm --without-m17n-flt
 --with-xwidgets --without-compress-install 'CFLAGS=-march=x86-64
 -mtune=generic -O2 -pipe -fstack-protector-strong -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 IMAGEMAGICK SOUND DBUS NOTIFY ACL GNUTLS
LIBXML2 FREETYPE LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 MODULES
XWIDGETS LIBSYSTEMD LCMS2

Important settings:
  value of $LC_COLLATE: 
  value of $LC_CTYPE: 
  value of $LC_MESSAGES: 
  value of $LC_MONETARY: 
  value of $LC_NUMERIC: 
  value of $LC_TIME: 
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8