Subject: Re: bug#75922: CPU hogs with pgtk

From: Pip Cet <[email-masked]>
Date: Wed, 29 Jan 2025 12:41:14 +0000

"Nicolas Sarlin" <[email-masked]> writes:

Thanks for the report! Debug suggestions below, but if you cannot or
would prefer not to any or all of that, that's perfectly okay, too!

> 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.

So this happens on the pgtk branch, but behavior on the master branch is
not noticeably slower than you'd expect?

> I report this as an emacs bug because it seems to only occurs when
> emacs is compiled with pgtk.

Are you running this on a Wayland setup, or on X (ignoring the popup)?

> If I rebuild emacs with "make bootstrap configure=default" the bug
> disapears.

Entirely?

> 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,

While a Lisp profile is always a good thing to have, I suspect a C
profile is more useful in this case.  Can you run

perf record -e instructions,cycles ./src/emacs -Q

then find a problematic workflow and wait for the problem to occur
(ideally, this will happen so often as to dominate the CPU trace), then
quit emacs in the ordinary fashion.  After that

perf report

will produce a basic output C profile.  It's both very long and somewhat
hard to read, but I think posting it to a bug number email should be
okay.  If you do this, please save these files for this specific run
somewhere:

./src/emacs
./src/emacs.pdmp
./perf.data
any coredumps you might have had

This will allow us to investigate the situation further if the function
names aren't enough to find the culprits.

Please also attempt to find the precise version of "corfu", as well as
any other packages that might seem like they're involved.

Thanks!
Pip