High CPU usage from the clojure-lsp server is plaguing me in the malli codebase (especially the malli.core namespace, which is ~2,700 lines of code).
Indentation behaviour causes the CPU spike:
• When I slurp/barf forms using smartparens (e.g. sp-forward-barf-sexp and sp-forward-slurp-sexp).
• Workspace log shows that the client sends the entire file's worth of content (~2,700 lines of code) to the LSP server, for any slurp/barf action. This is happening to provide clojure-lsp-powered re-indentation.
[Trace - 02:28:42 PM] Sending notification 'textDocument/didChange'.Params: { "textDocument": { "uri": "file:///path/to/malli/src/malli/core.cljc", "version": 30 }, "contentChanges": [ { "text": "(ns malli.core\n
... [SNIP] ...
the whole file worth of content... ... ..."
}
]
• I assume that's a bit much for cljfmt, because the rangeFormatting request times out.
lsp-request: Timeout while waiting for response. Method: textDocument/rangeFormatting
• Meanwhile, my Emacs remains frozen for several seconds (until the timeout).
• My Emacs becomes responsive if I turn off lsp indentation support by setting lsp-enable-indentation nil so that Emacs uses CIDER indentation.
Is this expected behaviour? i.e. sending the whole file, when modifying even a single form? I noticed older issues (like https://github.com/clojure-lsp/clojure-lsp/pull/795) which suggest the rangeFormatting performance hit should not occur any more.
I am on Emacs 28.1, using the latest available clojure-lsp server, and latest-available packages for clojure-lsp, lsp-mode, and smartparens.cljfmt range formatting is a feature with not a great performance indeed The best to do for your case is disable lsp-range-formatting and rely on format whole buffer which is pretty fast
We improved performance a lot, but for a 2700loc it may not be that fast
Thanks for the tip, @ericdallo... I appreciate all your work, stewardship, and community engagement gratitude