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

From: Nicolas Sarlin <[email-masked]>
Date: Wed, 29 Jan 2025 17:02:16 +0100

On Wed, 29 Jan 2025 at 14:06, Eli Zaretskii <[email-masked]> wrote:
>
> > From: Nicolas Sarlin <[email-masked]>
> > 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%.

I have seen a similar issue on lsp-mode closed so I tried to report it
here: https://github.com/emacs-lsp/lsp-mode/issues/3720
Similarly to what is reported in the lsp issue, this only occurs for
me when I mix lsp-mode, corfu and pgtk, so it's difficult to find the
exact root cause.