lsp-mode icon indicating copy to clipboard operation
lsp-mode copied to clipboard

lsp cpu too high

Open hikycool opened this issue 4 years ago • 20 comments

Thank you for the bug report

  • [X] I am using the latest version of lsp-mode related packages.
  • [X] I checked FAQ and Troubleshooting sections
  • [ ] You may also try reproduce the issue using clean environment using the following command
emacs -q -l lsp-start-plain.el

where lsp-start-plain.el can be downloaded here.

Bug description

Problem: LSP-Mode CPU high, When I visit redis code file: src/server.h and src/server.cc at same time with two split window. And the process alway keep almost 100% CPU.

The CPU report: lsp_cpu_high_report.log

Backend: ccls OS: macos11.6 also reproduce in ubuntu docker container emacs veresion: both emacs-27 emacs-28

My Configuration: ;;---------------LSP---------------------------------

(setq package-selected-packages '(lsp-mode yasnippet lsp-treemacs helm-lsp projectile hydra flycheck company avy which-key helm-xref dap-mode))

(when (cl-find-if-not #'package-installed-p package-selected-packages) (package-refresh-contents) (mapc #'package-install package-selected-packages))

;; sample `helm' configuration use https://github.com/emacs-helm/helm/ for details (helm-mode) (require 'helm-xref) (define-key global-map [remap find-file] #'helm-find-files) (define-key global-map [remap execute-extended-command] #'helm-M-x) (define-key global-map [remap switch-to-buffer] #'helm-mini)

(which-key-mode) (add-hook 'c-mode-hook 'lsp) (add-hook 'c++-mode-hook 'lsp) (add-hook 'go-mode-hook #'lsp-deferred)

(setq gc-cons-threshold (* 1024 1024 1024) read-process-output-max (* 1024 1024) treemacs-space-between-root-nodes nil company-idle-delay 0.0 company-minimum-prefix-length 1 lsp-idle-delay 0.5) ;; clangd is fast

(setq lsp-log-io nil)

;; ---- c/c++ ---------- (with-eval-after-load 'lsp-mode (add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration) (require 'dap-cpptools) (yas-global-mode))

(use-package ccls :hook ((c-mode c++-mode objc-mode cuda-mode) . (lambda () (require 'ccls) (lsp)))) (setq ccls-executable "/usr/local/bin/ccls") (setq ccls-args '("--log-file=/tmp/ccls.log")) ;; ---------------------

Steps to reproduce

Prepare

  • config emacs-lsp with ccls as my configuration
  • download redis source code

step1 open src/server.c

step2 C-x 3 split a new window

step3 open src/server.h

step4 And now the cpu turn high(almost 100%)

Backend: ccls OS: macos11.6 also reproduce in ubuntu docker container (User lsp-docker) emacs veresion: both emacs-27 emacs-28

Expected behavior

Expect: the CPU become normal load.

Which Language Server did you use?

Server: ccls

OS

MacOS

Error callstack

No response

Anything else?

No response

hikycool avatar Nov 21 '21 17:11 hikycool

step4 And now the cpu turn high(almost 100%)

What is the process taking 100% CPU?

The CPU report: lsp_cpu_high_report.log

This link is dead.

yyoncho avatar Nov 21 '21 17:11 yyoncho

step4 And now the cpu turn high(almost 100%)

What is the process taking 100% CPU?

The CPU report: lsp_cpu_high_report.log

This link is dead.

In report shows that:

image

reupdate report lsp_cpu_high_report (1).log :)

hikycool avatar Nov 22 '21 02:11 hikycool

(setq lsp-lens-enable nil) will make the issue go away. We have to figure out why lenses are so slow in c-mode.

yyoncho avatar Nov 22 '21 06:11 yyoncho

cc @ericdallo

yyoncho avatar Nov 22 '21 06:11 yyoncho

(setq lsp-lens-enable nil) will make the issue go away. We have to figure out why lenses are so slow in c-mode.

I have tried this config in my .emacs file, set it to be 'nil'. But there is another problem:

When I open the first *.c file, it works. Then I open another *.h file, lsp will connect to ccls process, and "lsp-lens-mode" will be enable automatically.

This would be another problem about that.

hikycool avatar Nov 22 '21 06:11 hikycool

When I open the first *.c file, it works. Then I open another *.h file, lsp will connect to ccls process, and "lsp-lens-mode" will be enable automatically.

This would be another problem about that.

I tested and it seems like it works fine.

yyoncho avatar Nov 22 '21 06:11 yyoncho

My lsp version: 20211023.2009. Should I upgrade or try older one ?

hikycool avatar Nov 22 '21 06:11 hikycool

Test with lsp-start-plain.el as described in bug template.

yyoncho avatar Nov 22 '21 07:11 yyoncho

Test with lsp-start-plain.el as described in bug template.

OK. I will try

hikycool avatar Nov 22 '21 07:11 hikycool

I wonder how many lenses C returns for a buffer to have this performance issue

ericdallo avatar Nov 22 '21 15:11 ericdallo

I wonder how many lenses C returns for a buffer to have this performance issue

Any way to show the number of lenses ? Or you can reproduce by using redis code file: src/server.h and src/server.c which i have met problem.

hikycool avatar Nov 22 '21 15:11 hikycool

@hikycool you can get it following this, this should help understand what server is returning on the textDocument/codeLens and textDocument/resolveCodeLens

ericdallo avatar Nov 22 '21 16:11 ericdallo

I wonder how many lenses C returns for a buffer to have this performance issue

Thanks a lot I have saw the log: " received response 'textDocument/codeLens'" json the src/server.h has 2581 response the src/server.c has has 459 response

hikycool avatar Nov 22 '21 17:11 hikycool

yeah, not sure if the server is using textDocument/resolveCodeLens which increase performance, otherwise client will request all those 2581 lens, right @yyoncho ?

ericdallo avatar Nov 22 '21 19:11 ericdallo

I believe the issue is a combination of our code and the slowness of the fontlock of c-mode. Most likely we should use a smarter way to check if the codelens is out of the visible area

yyoncho avatar Nov 22 '21 20:11 yyoncho

Reproduce with lsp-lens-enable default value t, when browsing emacs source code, especially large ones like src/eval.c. I turn it off and the problem goes away. I don't know what lsp-lens does anyway, so it doesn't affect me. :rofl:

TerryTsao avatar Mar 23 '22 03:03 TerryTsao

Hi! Is there any progress on this issue? Or is it irrelevant completely? Maybe popular LSP servers for C/C++ do not provide anything useful via lenses anyway? Is the last assumption true?

sceptical-coder avatar Aug 27 '22 00:08 sceptical-coder

For anyone interested, it seems that @MaskRay made some workaround to this in his config for emacs-ccls:

  • https://github.com/MaskRay/Config/blob/master/home/.config/doom/modules/private/my-cc/config.el#L74
  • https://github.com/MaskRay/Config/blob/master/home/.config/doom/modules/private/my-cc/config.el#L88

sceptical-coder avatar Aug 27 '22 21:08 sceptical-coder

For anyone interested, it seems that @MaskRay made some workaround to this in his config for emacs-ccls:

* https://github.com/MaskRay/Config/blob/master/home/.config/doom/modules/private/my-cc/config.el#L74

* https://github.com/MaskRay/Config/blob/master/home/.config/doom/modules/private/my-cc/config.el#L88

The issue is at least tolerable on my side with these tweaks.

sceptical-coder avatar Aug 27 '22 21:08 sceptical-coder

The performance on large files for lens is extremely poor. You should be able to reproduce the issue by trying to open one of the big files in the Surge synthesizer, https://github.com/surge-synthesizer/surge/blob/94e29c1a23758a4687c84fdb827769c9159945a9/src/surge-xt/gui/SurgeGUIEditor.cpp

Emacs will become basically unusable until lens is disabled.

mx avatar Sep 07 '22 03:09 mx