emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.79k stars 886 forks source link

Clangd/C++: Emacs freezes during completion #4486

Closed tinloaf closed 3 months ago

tinloaf commented 3 months ago

Thank you for the bug report

Bug description

I'm using emacs-lsp version 20240701.633 (from MELPA) with Clangd 18.1.8. I have a large C++ code base, so it is clear that collecting all completion suggestions might be long-running task. However, I expected this to happen asynchroneously (and it definitely worked that way before), and not block input.

For a couple of days now (weeks? I haven't worked on this large project for a while), my Emacs regularly completely freezes for ~5 seconds while it collects completions. Even repeatedly hitting C-g does not break out of the freeze.

I managed to reproduce the problem in the performance profiler:

       11264  82% - ...
       11264  82%  - company-capf--candidates
       11264  82%   - company-capf--candidates-1
       11264  82%    - completion-all-completions
       11264  82%     - apply
       11264  82%      - #<subr-native-elisp completion-all-completions>
       11264  82%       - completion--nth-completion
       11264  82%        - seq-some
       11264  82%         - seq-do
       11264  82%          - mapc
       11264  82%           - #<byte-code-function 4FD>
       11264  82%            - #<byte-code-function 49E>
       11264  82%             - lsp-completion-passthrough-all-completions
       11264  82%              - #<byte-code-function C1A>
       11264  82%               - #<byte-code-function C2E>
       11254  82%                - lsp-request-while-no-input
       11254  82%                 - sit-for
          88   0%                  - timer-event-handler
          88   0%                   - apply
          88   0%                    - company--sneaky-refresh
          59   0%                       redisplay_internal (C function)
          10   0%                - -map
          10   0%                 - #<byte-code-function C7E>
          10   0%                  - lsp-completion--guess-prefix
          10   0%                   - lsp--position-to-point
          10   0%                      lsp--line-character-to-point
        1513  11% - command-execute
        1418  10%  + byte-code
          95   0%  + funcall-interactively
         704   5% + redisplay_internal (C function)
          95   0% + timer-event-handler
          73   0% + flycheck-error-list-highlight-errors
           9   0% + jit-lock--antiblink-post-command

The *lsp-log* buffer does not contain anything suspicious, no log message is written at all during (resp. immediately after) the freeze. I also tried having a look at the IO-log, but as expected there's just a lot going on there while completions are requested, and I did not see anything suspicious.

Steps to reproduce

I'm afraid I cannot share the project this happens with. But I assume that any sufficiently large C++ project should work?

Expected behavior

Loading completions should happen asynchroneously, probably?

Which Language Server did you use?

lsp-clangd bundled with emacs-lsp version 20240701.633 (from MELPA) with Clangd 18.1.8.

OS

Linux

Error callstack

No response

Anything else?

I'm using Emacs version 30.0.50 built from the Emacs repository commit 38fe837f83448338b6ce5aaf771811ce6755d00a, which the Emacs repo master from 2024-05-15. The configure command used is:

./configure --without-pgtk --with-modules --with-xwidgets --with-imagemagick --with-json --with-x-toolkit=gtk3 --with-native-compilation --with-xft CFLAGS="-O3 -mtune=native -march=native -fomit-frame-pointer -pipe" CC="/usr/bin/gcc-13"
kiennq commented 3 months ago

Did you update to the new company-mode? Hmm, I'm not really sure where the issue would be. Btw, have you tried the blahgeek/emacs-lsp-booster? That would probably improve the perf in case you're working with large project.

tinloaf commented 3 months ago

@kiennq Thanks for the hint with company-mode. I could have guessed that myself from the backtrace… In fact it looks like this was a regression in company-mode. I just updated to the latest version and the problem is gone. :)

I'll check out emacs-lsp-booster nonetheless, thanks for the link!