This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-29
Channels
- # announcements (4)
- # babashka (38)
- # beginners (66)
- # calva (35)
- # cider (3)
- # clj-on-windows (19)
- # cljs-dev (2)
- # clojure (29)
- # clojure-europe (15)
- # clojure-norway (2)
- # clojurescript (43)
- # clr (7)
- # community-development (6)
- # events (3)
- # hoplon (5)
- # lsp (23)
- # malli (7)
- # matrix (9)
- # nbb (53)
- # off-topic (5)
- # overtone (1)
- # practicalli (2)
- # re-frame (6)
- # reagent (17)
- # reitit (11)
- # specter (5)
- # tools-build (7)
- # xtdb (22)
I’m using clojure-lsp with Emacs (pretty recent versions of everything), and I think clojure-lsp is doing unnecessary work when :paths-ignore-regex
is used.
I’ve used {:paths-ignore-regex [".*edn"]}
in my .lsp/config.edn
and run M-x lsp-workspace-restart
.
Now when I visit an edn file, as expected that stops showing lsp linting messages in Emacs (both in the echo area and lsp-ui), but I see activity in my clojure-lsp log file and I see that clojure-lsp is using the CPU.
Am I right in thinking that this is unexpected behaviour? (I was expecting clojure-lsp to be doing no significant work.)
For large edn files, this is enough to make Emacs sluggish.
For very large edn files, I think there may be a separate problem — I see stackoverflow errors in the logs.
I can create tickets for these if it would help.
I’ve added an Emacs hack to avoid using lsp for large files, so this is not at all urgent.
Here’s some of the log file output:
2023-05-29T13:39:04.938Z INFO [clojure-lsp.handlers:281] - :document-highlight 0ms
2023-05-29T13:39:04.939Z INFO [clojure-lsp.handlers:441] - :code-actions 1ms
2023-05-29T13:39:07.082Z INFO [clojure-lsp.handlers:441] - :code-actions 1ms
2023-05-29T13:39:12.359Z INFO [clojure-lsp.handlers:281] - :document-highlight 0ms
2023-05-29T13:39:12.360Z INFO [clojure-lsp.handlers:441] - :code-actions 1ms
2023-05-29T13:39:15.312Z INFO [clojure-lsp.handlers:281] - :document-highlight 0ms
2023-05-29T13:39:15.313Z INFO [clojure-lsp.handlers:441] - :code-actions 1ms
2023-05-29T13:39:17.632Z INFO [clojure-lsp.handlers:441] - :code-actions 1ms
2023-05-29T13:39:18.473Z INFO [clojure-lsp.handlers:281] - :document-highlight 0ms
2023-05-29T13:39:18.473Z INFO [clojure-lsp.handlers:274] - :document-symbol 1ms
2023-05-29T13:39:18.474Z INFO [clojure-lsp.handlers:441] - :code-actions 1ms
2023-05-29T13:39:18.475Z INFO [clojure-lsp.handlers:453] - :code-lens 0ms
2023-05-29T13:39:18.527Z INFO [clojure-lsp.feature.file-management:250] - changes analyzed by clj-depend took 0ms
2023-05-29T13:39:18.527Z INFO [clojure-lsp.feature.file-management:246] - changes analyzed by clj-kondo took 0ms
2023-05-29T13:39:18.528Z INFO [clojure-lsp.dep-graph:269] - :maintain-dep-graph 0ms
2023-05-29T13:39:18.528Z INFO [clojure-lsp.server:550] - :analyze-file 1ms
2023-05-29T13:39:18.530Z INFO [clojure-lsp.feature.file-management:139] - :reference-files/find 2ms
2023-05-29T13:39:18.530Z INFO [clojure-lsp.feature.file-management:137] - :notify-references 2ms
2023-05-29T13:39:18.558Z INFO [clojure-lsp.server:102] - :publish-diagnostics 0ms
2023-05-29T13:39:18.569Z INFO [clojure-lsp.handlers:441] - :code-actions 1ms
2023-05-29T13:40:06.097Z INFO [clojure-lsp.handlers:281] - :document-highlight 0ms
2023-05-29T13:40:06.099Z INFO [clojure-lsp.handlers:441] - :code-actions 1ms
Is that helpful?All of that is expected, since there lots of lap features and those can't be disable via server, but that's not what affects performance, you can see how they take 1ms or 0ms since probably there are no analysis for that file
Oh, those messages above were for a small file. Here’s some output for a large file. ^^
That exception is definitely not good, even so, not sure how other features are taking time if they have no analysis. Is it possible to create a repo showing those issues?
See the repo https://github.com/simon-katz/bug-report-clojure-lsp-ignored-edn-high-cpu
The above log messages came when playing with the file edn-files/big-2000-4.edn
.
As I said, I’ve added an Emacs hack to avoid using lsp for large files, so this is not at all urgent.
I think I know what it's happening, the :paths-ignore-regex
is used only for analysis of paths which happens for classpath analysis and project analysis during startup, but when you open a file manually we always analyze that file
https://github.com/clojure-lsp/clojure-lsp/blob/8a0c2e71681a0b9890b603dcea1ee29e918d58e3/lib/src/clojure_lsp/kondo.clj#L270
ah nvm, https://github.com/clojure-lsp/clojure-lsp/blob/8a0c2e71681a0b9890b603dcea1ee29e918d58e3/lib/src/clojure_lsp/kondo.clj#L381 for single files as well
I can repro the issue in the very-big edn filei, t's probably something to be fixed indeed
so, I found the root cause, it's caused by performance of rewrite-clj when parsing a huge node, like a map of 100k lines takes ~1s. I think that's is kinda of expected for a node of that size, what we can do is try to check :paths-ignore-regex for that as well, but it's not a analysis issue in the end
@U06A9U5RP I just made a commit to clojure-lsp's master improving paths-ignore-regex
to really ignore those features for LSP, that fixed the high cpu on that huge edn file, hope it works for you, you can test it with a nightly build #C032YH7P0R2
@UKFSJSM38
Ah, the nightly was built soon after your commit.
I’ve tried it out and, yes, it’s a lot better.
I still see the stack overflow errors in the logs, but I think clojure-lsp is using less CPU than before and Emacs is remaining pretty responsive.
Example log output for edn-files/very-big-10000-26.edn
:
2023-05-29T21:40:54.002Z INFO [clojure-lsp.handlers:143] - :hover - skipped
2023-05-29T21:40:54.013Z INFO [clojure-lsp.handlers:143] - :code-actions - skipped
2023-05-29T21:40:54.016Z INFO [clojure-lsp.handlers:143] - :document-highlight - skipped
2023-05-29T21:40:55.580Z INFO [clojure-lsp.handlers:143] - :code-actions - skipped
2023-05-29T21:40:55.583Z INFO [clojure-lsp.handlers:143] - :document-highlight - skipped
2023-05-29T21:40:55.585Z INFO [clojure-lsp.handlers:143] - :hover - skipped
2023-05-29T21:40:57.645Z ERROR [clojure-lsp.server:55] - Error receiving message: Internal error (-32603)
{:id 1663, :method "textDocument/documentSymbol"}
...
clojure.core/concat/fn core.clj: 727
clojure.core/seq core.clj: 139
...
clojure.core/concat/fn core.clj: 727
clojure.core/seq core.clj: 139
...
clojure.core/concat/fn core.clj: 727
clojure.core/seq core.clj: 139
...
clojure.core/concat/fn core.clj: 727
clojure.core/seq core.clj: 139
...
[...many more like the above lines, then...]
com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.throwNewStackOverflowError StackOverflowCheckImpl.java: 309
com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError StackOverflowCheckImpl.java: 329
com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError0 StackOverflowCheckImpl.java: 333
java.lang.StackOverflowError: