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.75k stars 872 forks source link

High latency while typing with ts-ls enabled #1450

Closed raxod502 closed 4 years ago

raxod502 commented 4 years ago

Describe the bug I experience momentary freezes of up to one second while typing in web-mode using the ts-ls language server, with Flycheck and Company enabled. Keystrokes are not dropped; their insertion is just delayed.

Here is a video of the behavior (note: moved from Google Drive to Nextcloud), also viewable below:

lag

To Reproduce Unfortunately, I have not been able to reproduce the behavior starting from a plain Emacs, so it is may be a conflict with something in my configuration. Furthermore, I can't reproduce it directly after a restart of Emacs, so it is likely the result of some state building up over time and causing a performance problem. Disabling Company removes the latency in the problematic session, but enabling Company in another session does not introduce the problem, so it's clearly not just Company.

Do you have any suggestions about what might be the bottleneck? If so, I could investigate further on my end next time the slowness reproduces. Perhaps it happens when I get a lot of language servers running (I have eight in the session which exhibits the problem, among texlab, bash-ls, clangd, hie, and ts-ls) or when there are many buffers handled by LSP (nineteen in this case).

Expected behavior Typing should not have noticeable latency.

Which Language Server did you use ts-ls

OS Manjaro Linux

Error callstack

Here is a selection of some of the slower performance diagnostics generated by enabling lsp-print-performance:

Perf> Request/Response
  ServerId: ts-ls
  Request: textDocument/completion (36970)
  Serialization took: 0.000483
  ServerTime: 0.054549
  Deserialization: 0.000001
  CallbackTime: 0.468447
Perf> Request/Response
  ServerId: ts-ls
  Request: textDocument/codeAction (36971)
  Serialization took: 0.001381
  ServerTime: 0.560562
  Deserialization: 0.000000
  CallbackTime: 0.000096
Perf> Request/Response
  ServerId: ts-ls
  Request: textDocument/signatureHelp (37020)
  Serialization took: 0.000466
  ServerTime: 0.600548
  Deserialization: 0.000000
  CallbackTime: 0.003203
Perf> Request/Response
  ServerId: ts-ls
  Request: textDocument/hover (37080)
  Serialization took: 0.000795
  ServerTime: 0.608043
  Deserialization: 0.000000
  CallbackTime: 0.000267

Here are the messages sent back and forth to ts-ls.

Here is my main *lsp-log*.

Here is the call stack from M-x profiler-*.

yyoncho commented 4 years ago

The profiler log suggests that you have lsp-print-io set to t. The client/server logging itself is very slow so the time is mostly spent in logging. Can you upload a performance profile with logging turned off?

raxod502 commented 4 years ago

Thanks -- will reopen when I reproduce with logging disabled.