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

laggy and stuck on lsp initialization process

Open eval-exec opened this issue 5 months ago • 3 comments
trafficstars

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
  • [x] You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

When I newly open a rust project, then start lsp, emacs will be laggy and stuck, it seems that rust-analzyer is sending to emacs many lsp message, and lsp-mode is processing the lsp message, cause emacs stuck.

Steps to reproduce

  1. git clone https://github.com/zed-industries/zed
  2. use emacs to open that project, open crates/zed/src/main.rs file
  3. launch lsp, then you can do cursor navigation, then you will feel the lsp-mode's initialization cause emacs laggy and stuck for about 10 seconds.

Expected behavior

lsp-mode should't cause emacs stuck and laggy.

Which Language Server did you use?

rust-analyzer

OS

Linux

Error callstack

I do profiling during the lsp initialization stuck:

      581068  95% - #<interpreted-function BDD5>
      581068  95%  - let
      579178  94%   - while
      575402  94%    - if
      575402  94%     - let*
      574804  94%      - if
      555983  91%       - prog1
      545675  89%          setq
       18821   3%       - progn
       12458   2%        - setq
        1525   0%         - lsp--get-body-length
        1327   0%          - mapcar
        1228   0%           - lsp--parse-header
        1228   0%            - let
         830   0%             - if
         731   0%              - progn
         731   0%               - progn
         731   0%                - or
         731   0%                 - let*
         300   0%                  - while
         300   0%                   - and
         200   0%                    - setq
         100   0%                       1+
         100   0%                      <
         199   0%             - progn
         199   0%              - setq
         100   0%                 s-trim-left
         100   0%               string-match
          99   0%           - split-string
          99   0%            - substring

Anything else?

Another profiling:

     6885379  82% - #<interpreted-function 779>
     6884981  82%  - let
     6827840  81%   - while
     6792923  81%    - if
     6792524  81%     - let*
     6789883  81%      - if
     4366549  52%       - prog1
     1720587  20%        - setq
         199   0%           substring
         100   0%          substring
     2423206  28%       - progn
     2223457  26%        - condition-case
     2223357  26%         - let
     2222792  26%          - save-current-buffer
     2211372  26%           - unwind-protect
     2206418  26%            - progn
     1663071  19%             - setq
     1662771  19%              - cons
         592   0%                 json-parse-buffer
       16634   0%             - decode-coding-region
       10824   0%              - symbol-overlay-refresh
         398   0%               - if
         198   0%                - or
         198   0%                 - not
         198   0%                    or
       14815   0%             - apply
       14518   0%              - insert
       10561   0%                 symbol-overlay-refresh
         198   0%              - nreverse
         198   0%                 prog1
         199   0%               goto-char
        4854   0%            - work-buffer--release
         882   0%             - symbol-overlay-refresh
         485   0%              - if

eval-exec avatar May 25 '25 08:05 eval-exec

Can you try to go to lsp-mode.el and do a M-x eval-buffer then try to reinitialize the rust lsp again with profile taken? That would expand the function name more and give us more point to investigate.

kiennq avatar May 25 '25 09:05 kiennq

Can you try to go to lsp-mode.el and do a M-x eval-buffer then try to reinitialize the rust lsp again with profile taken? That would expand the function name more and give us more point to investigate.

     2355589  93% - #<interpreted-function C61>
     2355490  93%  - let
     2334195  92%   - while
     2316726  92%    - if
     2316626  92%     - let*
     2314950  92%      - if
     1172536  46%       - progn
      610887  24%        - setq
      579275  23%         - lsp--get-body-length
      578220  23%          - mapcar
      574234  22%           - lsp--parse-header
        9940   0%            - let
        5086   0%             - progn
        4689   0%              - setq
        4590   0%               - s-trim-left
          99   0%                  substring
          99   0%                - #<byte-code-function 9CF9>
          99   0%                   set-match-data
        3335   0%             - if
        3135   0%              - progn
        3135   0%               - progn
        3135   0%                - or
        3135   0%                 - let*
        2180   0%                  - while
        1882   0%                   - and
        1190   0%                    - progn
         893   0%                     - if
         299   0%                      - or
         100   0%                         >
         297   0%                       setq
         299   0%                      <
         200   0%                    - setq
         100   0%                       1+
         600   0%               string-match
        1103   0%           - split-string
         200   0%              string-match
         198   0%            - substring
          99   0%             - or
          99   0%                string-search
         814   0%          - let
         318   0%           - cdr
          99   0%              assoc
         199   0%           - if
         199   0%              string-to-number
          99   0%         - substring
          99   0%            +
      561551  22%        - condition-case
      561257  22%         - let
      560859  22%          - save-current-buffer
      556496  22%           - unwind-protect
      555801  22%            - progn
      548190  21%             - setq
      548190  21%              - cons
         496   0%               - json-parse-buffer
         100   0%                  if
        1873   0%             - apply
        1177   0%              - insert
         406   0%               - symbol-overlay-refresh
         307   0%                - if
         307   0%                 - or
         208   0%                  - not
          99   0%                   - lsp--client-disabled-p
          99   0%                    - seq-some
          99   0%                     - function
          99   0%                      - cconv-make-interpreted-closure
          99   0%                       - cconv-fv
          99   0%                        - cconv-analyze-form
          99   0%                         - cconv--analyze-function
          99   0%                          - cconv-analyze-form
          99   0%                           - cconv-analyze-form
          99   0%                            - cconv-analyze-form
          99   0%                             - cconv-analyze-form
          99   0%                              - #<byte-code-function 4D7>
          99   0%                               - cconv-analyze-form

eval-exec avatar May 25 '25 11:05 eval-exec

I ask claude: https://claude.ai/public/artifacts/e05b6d34-0f78-4319-9c58-67a860fa266e

eval-exec avatar May 25 '25 12:05 eval-exec