GNU bug report logs - #52761
29.0.50; (--with-pgtk) poor point movement performance when global-flycheck-mode is called during start-up

Previous Next

Package: emacs;

Reported by: Simon Pugnet <simon <at> polaris64.net>

Date: Thu, 23 Dec 2021 19:52:02 UTC

Severity: normal

Found in version 29.0.50

Done: Yuuki Harano <masm+emacs <at> masm11.me>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 52761 in the body.
You can then email your comments to 52761 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#52761; Package emacs. (Thu, 23 Dec 2021 19:52:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Simon Pugnet <simon <at> polaris64.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 23 Dec 2021 19:52:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Simon Pugnet <simon <at> polaris64.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; (--with-pgtk) poor point movement performance when
 global-flycheck-mode is called during start-up
Date: Thu, 23 Dec 2021 19:51:09 +0000
[Message part 1 (text/plain, inline)]
I've noticed a strange performance issue with Emacs when built
--with-pgtk, but only when global-flycheck-mode is called during Emacs
start-up.

To reproduce, download and extract the following packages: -

 - Flycheck: https://melpa.org/#/flycheck
 - Dash.el (dependency): https://elpa.gnu.org/packages/dash.html

Assuming these are at ~/flycheck and ~/dash, perform the following
steps: -

1. Create ~/init.el as follows: -

#+begin_src emacs-lisp
(add-to-list 'load-path (expand-file-name "~/flycheck"))
(add-to-list 'load-path (expand-file-name "~/dash"))
(require 'flycheck)
(global-flycheck-mode)
#+end_src

2. Run Emacs, loading this init.el file: "emacs -Q -l ~/init.el"

Now, when I use C-n/C-p to move around any buffer, there is a very
short but noticeable delay between key-presses and the point actually
moving. It's quite easy to notice when compared to the same Emacs run
as just "emacs -Q".

This only happens when Emacs is built --with-pgtk (and other features
as below). If I remove --with-pgtk, this delay disappears. Also, if I
do not call global-flycheck-mode during initialisation and instead
call it manually at some later stage, the delay also does not appear.
It only seems to happen when the global-flycheck-mode call is done
during initialisation.

Please let me know if there is any more information I can provide.

All the best and thanks in advance for your help,

Simon


In GNU Emacs 29.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version
3.24.31, cairo version 1.17.4)
 of 2021-12-23 built on tikal
Repository revision: 2fa7feca336dd16c57ffef072e0f0da6fffe4c5f
Repository branch: master
Windowing system distributor 'System Description: Arch Linux

Configured using:
 'configure --with-native-compilation --with-modules --with-json
 --with-xinput2 --with-pgtk'

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

Important settings:
  value of $LC_CTYPE: en_GB.UTF-8
  value of $LANG: en_GB.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

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
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
/usr/local/share/emacs/29.0.50/lisp/emacs-lisp/eieio-compat hides
/usr/local/share/emacs/29.0.50/lisp/obsolete/eieio-compat

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media rmc puny
dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg
rfc6068 epg-config gnus-util text-property-search time-date seq gv
subr-x byte-opt bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils
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
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 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 emoji-zwj
charscript
charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button 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
dbusbind inotify dynamic-setting system-font-setting
font-render-setting
cairo move-toolbar gtk x-toolkit pgtk lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 56008 9769)
 (symbols 48 5662 1)
 (strings 32 16131 1632)
 (string-bytes 1 536291)
 (vectors 16 11510)
 (vector-slots 8 261217 13969)
 (floats 8 26 26)
 (intervals 56 224 0)
 (buffers 992 11))
[attachment.sig (application/pgp-signature, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52761; Package emacs. (Thu, 06 Jan 2022 14:57:02 GMT) Full text and rfc822 format available.

Message #8 received at 52761 <at> debbugs.gnu.org (full text, mbox):

From: Yuuki Harano <masm+emacs <at> masm11.me>
To: simon <at> polaris64.net
Cc: 52761 <at> debbugs.gnu.org
Subject: Re: bug#52761: 29.0.50; (--with-pgtk) poor point movement
 performance when global-flycheck-mode is called during start-up
Date: Thu, 06 Jan 2022 23:56:17 +0900 (JST)
[Message part 1 (text/plain, inline)]
On Thu, 23 Dec 2021 19:51:09 +0000,
	Simon Pugnet <simon <at> polaris64.net> wrote:
> I've noticed a strange performance issue with Emacs when built
> --with-pgtk, but only when global-flycheck-mode is called during Emacs
> start-up.

Please try the attached patch.

-- 
Yuuki Harano
[keypress-delay.diff (text/x-patch, inline)]
diff --git a/src/xgselect.c b/src/xgselect.c
index 674c259db7..14a8c73541 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -96,10 +96,21 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds,
   int n_gfds, retval = 0, our_fds = 0, max_fds = fds_lim - 1;
   int i, nfds, tmo_in_millisec, must_free = 0;
   bool need_to_dispatch;
+#ifdef HAVE_PGTK
+  bool already_has_events = false;
+#endif
 
   context = g_main_context_default ();
   acquire_select_lock (context);
 
+#ifdef HAVE_PGTK
+  {
+    int errno_back = errno;
+    already_has_events = g_main_context_pending (context);
+    errno = errno_back;
+  }
+#endif
+
   if (rfds) all_rfds = *rfds;
   else FD_ZERO (&all_rfds);
   if (wfds) all_wfds = *wfds;
@@ -146,10 +157,41 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds,
 	tmop = &tmo;
     }
 
+#ifndef HAVE_PGTK
   fds_lim = max_fds + 1;
   nfds = thread_select (pselect, fds_lim,
 			&all_rfds, have_wfds ? &all_wfds : NULL, efds,
 			tmop, sigmask);
+#else
+  /*
+    On PGTK, when you type a key, the key press event are received,
+    and one more key press event seems to be received internally.
+    The second event is not via a socket, so there are weird status:
+      - socket read buffer is empty
+      - a key press event is pending
+    In that case, we should not sleep, and dispatch the event immediately.
+    Bug#52761
+   */
+  if (!already_has_events)
+    {
+      fds_lim = max_fds + 1;
+      nfds = thread_select (pselect, fds_lim,
+			    &all_rfds, have_wfds ? &all_wfds : NULL, efds,
+			    tmop, sigmask);
+    }
+  else
+    {
+      /* Emulate return values */
+      nfds = 1;
+      FD_ZERO(&all_rfds);
+      if (have_wfds)
+	FD_ZERO(&all_wfds);
+      if (efds)
+	FD_ZERO(efds);
+      our_fds++;
+    }
+#endif
+
   if (nfds < 0)
     retval = nfds;
   else if (nfds > 0)

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52761; Package emacs. (Thu, 06 Jan 2022 15:12:02 GMT) Full text and rfc822 format available.

Message #11 received at 52761 <at> debbugs.gnu.org (full text, mbox):

From: Simon Pugnet <simon <at> polaris64.net>
To: Yuuki Harano <masm+emacs <at> masm11.me>
Cc: 52761 <at> debbugs.gnu.org
Subject: Re: bug#52761: 29.0.50;
 (--with-pgtk) poor point movement performance when
 global-flycheck-mode is called during start-up
Date: Thu, 06 Jan 2022 15:11:33 +0000
[Message part 1 (text/plain, inline)]
"Yuuki Harano" <masm+emacs <at> masm11.me> writes:

> On Thu, 23 Dec 2021 19:51:09 +0000,
> 	Simon Pugnet <simon <at> polaris64.net> wrote:
>> I've noticed a strange performance issue with Emacs when built
>> --with-pgtk, but only when global-flycheck-mode is called during
>> Emacs
>> start-up.
>
> Please try the attached patch.

That patch seems to resolve the problem for me! Thank you for looking
into this bug.

Kind regards,

--
Simon Pugnet
https://www.polaris64.net/
[attachment.sig (application/pgp-signature, attachment)]

Reply sent to Yuuki Harano <masm+emacs <at> masm11.me>:
You have taken responsibility. (Fri, 07 Jan 2022 15:02:01 GMT) Full text and rfc822 format available.

Notification sent to Simon Pugnet <simon <at> polaris64.net>:
bug acknowledged by developer. (Fri, 07 Jan 2022 15:02:01 GMT) Full text and rfc822 format available.

Message #16 received at 52761-done <at> debbugs.gnu.org (full text, mbox):

From: Yuuki Harano <masm+emacs <at> masm11.me>
To: simon <at> polaris64.net
Cc: 52761-done <at> debbugs.gnu.org
Subject: Re: bug#52761: 29.0.50; (--with-pgtk) poor point movement
 performance when global-flycheck-mode is called during start-up
Date: Sat, 08 Jan 2022 00:01:08 +0900 (JST)
On Thu, 06 Jan 2022 15:11:33 +0000,
	Simon Pugnet <simon <at> polaris64.net> wrote:
> That patch seems to resolve the problem for me! Thank you for looking
> into this bug.

Thanks for the confirmation.
I fixed on master, and I'm closing this issue.

-- 
Yuuki Harano




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 05 Feb 2022 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 81 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.