GNU bug report logs - #75922
CPU hogs with pgtk

Previous Next

Package: emacs;

Reported by: Nicolas Sarlin <nico.sarlin <at> gmail.com>

Date: Wed, 29 Jan 2025 11:16:02 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Nicolas Sarlin <nico.sarlin <at> gmail.com>
Subject: bug#75922: closed (Re: bug#75922: CPU hogs with pgtk)
Date: Sat, 08 Feb 2025 09:48:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#75922: CPU hogs with pgtk

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 75922 <at> debbugs.gnu.org.

-- 
75922: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=75922
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Eli Zaretskii <eliz <at> gnu.org>
To: Pip Cet <pipcet <at> protonmail.com>
Cc: nico.sarlin <at> gmail.com, 75922-done <at> debbugs.gnu.org
Subject: Re: bug#75922: CPU hogs with pgtk
Date: Sat, 08 Feb 2025 11:46:46 +0200
> Date: Thu, 30 Jan 2025 08:48:12 +0000
> From: Pip Cet <pipcet <at> protonmail.com>
> Cc: Eli Zaretskii <eliz <at> gnu.org>, 75922 <at> debbugs.gnu.org
> 
> "Nicolas Sarlin" <nico.sarlin <at> gmail.com> writes:
> 
> > On Wed, Jan 29, 2025, 18:29 Pip Cet <pipcet <at> protonmail.com> wrote:
> >
> >  "Nicolas Sarlin" <nico.sarlin <at> gmail.com> writes:
> >
> >  > On Wed, 29 Jan 2025 at 14:06, Eli Zaretskii <eliz <at> gnu.org> wrote:
> >  >>
> >  >> > From: Nicolas Sarlin <nico.sarlin <at> gmail.com>
> >  >> > Date: Wed, 29 Jan 2025 12:05:16 +0100
> >  >> >
> >  >> > I'm using lsp-mode with corfu on the emacs-30 branch, and I get extremely
> >  >> > frequent CPU hogs (CPU runs at 100% for a few seconds) while typing
> >  >> > code. I report this as an emacs bug because it seems to only occurs when
> >  >> > emacs is compiled with pgtk. If I rebuild emacs with "make bootstrap
> >  >> > configure=default" the bug disapears.
> >  >> >
> >  >> > Here is a profiler record:
> >  >> >        11152  91% - corfu--post-command
> >  >> >        11152  91%  - corfu--exhibit
> >  >> >        11043  90%   - corfu--update
> >  >> >        10891  88%    - corfu--recompute
> >  >> >        10891  88%     - corfu--filter-completions
> >  >> >        10891  88%      - completion-all-completions
> >  >> >        10891  88%       - completion--nth-completion
> >  >> >        10891  88%        - seq-some
> >  >> >        10891  88%         - seq-do
> >  >> >        10891  88%          - mapc
> >  >> >        10891  88%           - #<byte-code-function AC1>
> >  >> >        10891  88%            - #<byte-code-function AD0>
> >  >> >        10891  88%             - lsp-completion-passthrough-all-completions
> >  >> >        10891  88%              - #<byte-code-function 4B5>
> >  >> >        10891  88%               - #<byte-code-function 4DE>
> >  >> >        10888  88%                - lsp-request-while-no-input
> >  >> >        10888  88%                 - sit-for
> >  >>
> >  >> The profile says most of the time is spent in sit-for called from
> >  >> lsp-request-while-no-input.  First, sit-for is not supposed to consume
> >  >> CPU, because it's a waiting function.  Are you sure this profile was
> >  >> taken when Emacs was hogging CPU?
> >  >>
> >  >> And second, lsp-mode is not part of Emacs, so if indeed the above is a
> >  >> profile representative of high CPU load, I suggest to report this to
> >  >> the developers of lsp-mode first, even though the problem appears only
> >  >> in the PGTK build.
> >  >>
> >  >> Thanks.
> >  >
> >  > Hi, thank you for your answer.
> >  > Yes, this profile was collected during an emacs freeze. It took me a
> >  > few second (maybe 10) after `profiler-start` to trigger the freeze,
> >  > then again a few seconds of freeze, then I ran `profiler-stop`
> >  > directly after. During the freeze I had one CPU core constantly
> >  > running at 100%.
> >
> >  My guess is it's this code in lsp-mode.el:
> >
> >                (while (not (or resp-error resp-result (input-pending-p)))
> >                  (catch 'lsp-done
> >                    (sit-for
> >                     (if expected-time (- expected-time send-time) 1)))
> >                  (setq send-time (float-time))
> >                  (when (and expected-time (< expected-time send-time))
> >                    (error "Timeout while waiting for response.  Method: %s" method)))
> >
> >  This code appears to want to reliquish the CPU for the next
> >  lsp-response-timeout (default 10) seconds, so it calls sit-for with an
> >  argument close to 10.0, or 1 if no timeout is set.
> >
> >  The behavior of sit-for is to return immediately if there is pending
> >  input, ignoring the timeout argument.
> >
> >  In this case, this loop will use all of the CPU until whatever it is
> >  actually waiting for happens, assuming a single "input event" (a
> >  keypress is one, but certain kinds of mouse movement or a similar event
> >  can also cause sit-for to exit immediately) has happened.
> >
> >  Some other places also in that file may work less than optimally when
> >  sit-for returns immediately, also.
> >
> >  So this seems most likely like a bug there, and it may be triggered more
> >  by pgtk/wayland because of such details as key repeat being handled by
> >  the application rather than what used to be the X server.
> >
> >  I'm slightly surprised at your perf report, but at least the last part
> >  doesn't seem inconsistent with that interpretation.
> >
> >  Once the bug is fixed, it would be great to hear how the documentation
> >  of sit-for could be improved.  If that doesn't work, we might even want
> >  to detect situations in which sit-for is called repeatedly with a
> >  timeout argument even though no input was handled in the meantime.
> >
> >  Pip
> >
> > Thank you for your help! I will report it to lsp-mode with the info you provided.
> >
> > Sorry for the disturbance
> 
> No problem at all. I think the API is a bit confusing, and the
> documentation doesn't warn about it sufficiently.  Both can be changed.

I think we can close this bug now.

[Message part 3 (message/rfc822, inline)]
From: Nicolas Sarlin <nico.sarlin <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: CPU hogs with pgtk
Date: Wed, 29 Jan 2025 12:05:16 +0100
[Message part 4 (text/plain, inline)]
Hello,
I'm using lsp-mode with corfu on the emacs-30 branch, and I get extremely
frequent CPU hogs (CPU runs at 100% for a few seconds) while typing
code. I report this as an emacs bug because it seems to only occurs when
emacs is compiled with pgtk. If I rebuild emacs with "make bootstrap
configure=default" the bug disapears.

Here is a profiler record:
       11152  91% - corfu--post-command
       11152  91%  - corfu--exhibit
       11043  90%   - corfu--update
       10891  88%    - corfu--recompute
       10891  88%     - corfu--filter-completions
       10891  88%      - completion-all-completions
       10891  88%       - completion--nth-completion
       10891  88%        - seq-some
       10891  88%         - seq-do
       10891  88%          - mapc
       10891  88%           - #<byte-code-function AC1>
       10891  88%            - #<byte-code-function AD0>
       10891  88%             - lsp-completion-passthrough-all-completions
       10891  88%              - #<byte-code-function 4B5>
       10891  88%               - #<byte-code-function 4DE>
       10888  88%                - lsp-request-while-no-input
       10888  88%                 - sit-for
          82   0%                  + redisplay_internal (C function)
          18   0%                  + #<byte-code-function 31C>
           3   0%                + lsp--text-document-position-params
         152   1%    + redisplay
          89   0%   + posn-at-point
          20   0%   + corfu--candidates-popup
         674   5% + command-execute
         269   2% + redisplay_internal (C function)
          74   0% + #<byte-code-function 31C>
          59   0% + timer-event-handler
          25   0% + ...

Please tell me if you need more information,
Thank you for your help


In GNU Emacs 30.0.93 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.43, cairo version 1.18.2) of 2025-01-27 built on zama-laptop
Repository revision: 84595cbcc78b1ea44302f22b83a7d722940c6e49
Repository branch: emacs-30
System Description: Arch Linux

Configured using:
 'configure --with-pgtk'

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

Important settings:
  value of $LC_MONETARY: fr_FR.UTF-8
  value of $LC_NUMERIC: fr_FR.UTF-8
  value of $LC_TIME: fr_FR.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Message

Minor modes in effect:
  editorconfig-mode: t
  global-corfu-mode: t
  corfu-mode: t
  mml-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: message-do-auto-fill
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  abbrev-mode: t
  hs-minor-mode: t

Load-path shadows:
None found.

Features:
(mailalias mailclient textsec uni-scripts idna-mapping ucs-normalize
uni-confusable textsec-check ispell help-fns profiler flymake
lsp-diagnostics lsp-headerline lsp-modeline lsp-lens view lsp-zig
lsp-yang lsp-yaml lsp-xml lsp-wgsl lsp-volar lsp-vimscript lsp-vhdl
lsp-vetur lsp-verilog lsp-vala lsp-v lsp-typespec lsp-typeprof lsp-ttcn3
lsp-ts-query lsp-trunk lsp-toml lsp-tilt lsp-tex lsp-terraform
lsp-svelte lsp-steep lsp-sqls lsp-sql lsp-sorbet lsp-solidity
lsp-solargraph lsp-semgrep lsp-rust lsp-ruff lsp-ruby-syntax-tree
lsp-ruby-lsp lsp-rubocop lsp-roslyn lsp-roc lsp-rf lsp-remark lsp-racket
lsp-r lsp-qml lsp-pylsp lsp-pyls lsp-pwsh lsp-purescript lsp-pls lsp-php
lsp-perlnavigator lsp-perl lsp-openscad lsp-ocaml lsp-nushell lsp-nix
lsp-nim lsp-nginx lsp-nextflow lsp-move lsp-mojo lsp-mint lsp-meson
lsp-mdx lsp-matlab lsp-marksman lsp-markdown lsp-magik lsp-fennel
lsp-lua lsp-lisp lsp-kubernetes-helm lsp-kotlin lsp-json lsp-jq
lsp-idris lsp-haxe lsp-hack lsp-groovy lsp-graphql lsp-golangci-lint
lsp-glsl lsp-gleam lsp-gdscript lsp-fsharp lsp-futhark lsp-fortran
lsp-eslint lsp-erlang lsp-emmet lsp-elm lsp-elixir lsp-earthly
lsp-dockerfile lsp-dhall lsp-d lsp-cypher lsp-cucumber lsp-copilot
lsp-css lsp-csharp lsp-crystal lsp-credo lsp-cobol lsp-cmake lsp-clojure
lsp-clangd lsp-bufls lsp-beancount lsp-bash lsp-awk lsp-autotools
lsp-astro lsp-asm lsp-ansible lsp-angular lsp-ada lsp-actionscript
vc-git diff-mode track-changes vc-dispatcher misearch multi-isearch
shadow sort mail-extr emacsbug editorconfig editorconfig-core
editorconfig-core-handle editorconfig-fnmatch rust-utils rust-prog-mode
rust-mode rust-playpen rust-cargo rust-common rust-rustfmt rust-compile
rust-mode-autoloads corfu compat corfu-autoloads lsp-ui lsp-ui-doc
lsp-ui-imenu lsp-ui-peek lsp-ui-sideline find-func goto-addr lsp-ui-util
face-remap lsp-ui-autoloads lsp-javascript lsp-html ido lsp-icons dom
lsp-go lsp-completion lsp-semantic-tokens lsp-mode comp comp-cstr
lsp-protocol xref tree-widget spinner markdown-mode lv imenu ht
filenotify f ewoc lsp-mode-autoloads s f-autoloads s-autoloads inline
dash ht-autoloads info dash-autoloads spinner-autoloads pcase color
thingatpt noutline outline markdown-mode-autoloads easy-mmode warnings
lv-autoloads loaddefs-gen lisp-mnt radix-tree tar-mode arc-mode
archive-mode cus-edit pp cus-start cus-load wid-edit mm-archive message
sendmail yank-media dired dired-loaddefs rfc822 mml mml-sec epa derived
gnus-util time-date mailabbrev gmm-utils mailheader mm-decode mm-bodies
mm-encode mail-utils gnutls network-stream url-cache url-http url-auth
mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr url-gw
nsm puny compile text-property-search comint ansi-osc ansi-color ring
comp-run comp-common rx epg rfc6068 epg-config use-package-ensure
project finder-inf package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie generate-lisp-file
url-domsuf url-util mailcap url-handlers url-parse auth-source eieio
eieio-core icons password-cache json subr-x map byte-opt url-vars
cl-macs gv cl-extra help-mode cl-seq use-package-core cl-loaddefs cl-lib
bytecomp byte-compile rmc iso-transl tooltip cconv eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/pgtk-win pgtk-win term/common-win touch-screen 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 dbusbind inotify
dynamic-setting system-font-setting font-render-setting cairo gtk pgtk
lcms2 multi-tty move-toolbar make-network-process native-compile emacs)

Memory information:
((conses 16 1165555 834435) (symbols 48 39223 34) (strings 32 289158 102434)
 (string-bytes 1 6818416) (vectors 16 137350) (vector-slots 8 1772485
595550)
 (floats 8 631 1411) (intervals 56 5673 2695) (buffers 992 36))
[Message part 5 (text/html, inline)]

This bug report was last modified 159 days ago.

Previous Next


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