eclipse / lsp4e

Language Server Protocol support in Eclipse IDE
Eclipse Public License 2.0
60 stars 53 forks source link

Performance issue when formatting a large file #932

Closed ghentschke closed 5 months ago

ghentschke commented 5 months ago

Given is a large file (~5000 lines). When performing a formatting with many formatted lines (e.g. by changing the indent with) via LSP, the folding and semantic highlighting reconciler are triggered for every queued change event in the document. Since both reconcilers perform on the whole document they should be performed only once, when the document has been modfied and not for each quewed document change.

A formatting with many formatted lines result in many queued change events:

I[09:48:20.585] <-- textDocument/didChange
I[09:48:20.585] <-- textDocument/didChange
I[09:48:20.585] <-- textDocument/didChange
I[09:48:20.585] <-- textDocument/didChange
I[09:48:20.586] <-- textDocument/didChange
I[09:48:20.586] <-- textDocument/didChange
...

which results in many (thousands!) consecutive formatting and semantic highlighting reconciler runs:

I[09:48:21.774] <-- textDocument/semanticTokens/full("483")
I[09:48:21.779] --> reply:textDocument/semanticTokens/full("483") 4 ms
I[09:48:21.835] <-- textDocument/foldingRange("484")
I[09:48:21.917] --> reply:textDocument/foldingRange("484") 81 ms
I[09:48:22.340] <-- textDocument/semanticTokens/full("485")
...

When logging to lsp4e console an out of memory occurs.

Step to reproduce:

  1. Open a large file in LSP backed editor
  2. Modify the formatting settings in way that many lines will be changed (e.g. change the IndentWidth in .clang-format file when using clangd as LS)
  3. Select all (Ctrl+a)
  4. Select in editor context menu -> Source -> Format
  5. Wait for the reconciler to be triggered (its not triggered immediately, it can take up to a few seconds, or scrolling around in the source document my trigger it as well)