You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of clojure-emacs/cider#3456 I just upgraded to clojure-mode-20230911.1653, which seems to have caused a tremendous performance regression around indenting forms.
Expected behavior
Indentation is fast enough not to interrupt flow
Actual behavior
A ~30-line let or do now takes just under 10 seconds to indent.
A ~400-line buffer froze emacs for about a minute while indenting.
Carriage return at the end of a line has a sub-second but noticeable delay.
Apparently "electric / aggressive indentation modes" can query cider-current-repl which can be relatively slow, and noticeably slow if repeated enough times.
Would very much appreciate if you could verify a specific cause.
Apparently "electric / aggressive indentation modes" can query cider-current-repl which can be relatively slow, and noticeably slow if repeated enough times.
I think this is the right direction, because I think I just found a huge supporting clue of several parts:
when there are 0 REPLs running, indentation is instant; I don't see a progress % in minibuffer
while cider-connected to a babashka REPL in the current buffer, indentation is fast enough but I do notice a flicker of progress % in the minibuffer and there's a noticeable subsecond lag
while that babashka REPL is running elsewhere, indentation in my clojuredart buffer (clojure-mode but no REPL) is very very slow (for the same form as in babashka buffer!)
Could you please (benchmark-elapse (cider-current-repl)) for each case?
Expanding on that, (cider-current-repl) can invoke a function named cider--sesman-friendly-session-p.
Assuming a given (cider-current-repl) call for a specific scenario is slow, please also benchmark (cider-debug-sesman-friendly-session-p) which is a special defun that exercises cider--sesman-friendly-session-p. It's sensitive to the current buffer you invoke it from (with M-:)
If (cider-debug-sesman-friendly-session-p) performs slowly, please profile it and share which specific function calls within it are to blame for the slowness.
I'd much appreciate if you can try it locally. If you use ELPA, one way is to download those two files, place them in ~/.emacs.d/elpa/cider*, remove any .elc files and restart Emacs.
I'd much appreciate if you can try it locally. If you use ELPA, one way is to download those two files, place them in ~/.emacs.d/elpa/cider*, remove any .elc files and restart Emacs.
Thanks, I really appreciate you chasing these leads. I got those two files downloaded and running and see no change. (I confirmed they were the running code with describe-mode and some jump-to-def, though I didn't see any .elc files to delete — not sure if that could be an issue?)
I also noticed that the slowdown in the clojure-mode-but-no-CIDER-REPL only occurs when there's a cider-connect'd babashka REPL running elsewhere, not when I have a cider-jack-in'd-JVM-REPL running elsewhere with the following start-up command:
Also, a quick way to check if the new code is being used is M-: cider--sesman-friendly-session-calculated-at in the problematic buffer - it should have a non-nil value.
benchmark
(("path/to/app.cljd" "was not determined to belong to classpath:" nil "or classpath-roots:" nil))
0.032754
(("path/to/app.cljd" "was not determined to belong to classpath:" nil "or classpath-roots:" nil))
0.030909
(("path/to/app.cljd" "was not determined to belong to classpath:" nil "or classpath-roots:" nil))
0.032258
(("path/to/app.cljd" "was not determined to belong to classpath:" nil "or classpath-roots:" nil))
0.028817
(("path/to/app.cljd" "was not determined to belong to classpath:" nil "or classpath-roots:" nil))
0.030899
So, the process isn't holding any of the big objects to be cached. Maybe that's related to the nature of bb? Since it's an nrepl server I'd imagine it's a persistent process, but also bb is oriented towards one-off things (i.e., they run and complete very quickly) so maybe something is 'one-off' there?
That would mean a bb repl is unable to cache anything.
The exact question is whether cider's nrepl-server process that is backed by bb is a "true" persistent server, or contrariwise something that is spawned on demand for each request.
Not sure if Michiel implemented that, but he might know!
Activity
vemv commentedon Sep 12, 2023
Thanks much for the report!
Will see if I can repro, if so I'll try to bisect its cause.
vemv commentedon Sep 12, 2023
I can't repro any sort of slowness - I can indent my whole ns buffer with clojure-mode in an instant.
Are you using something like electric-indent-mode, clojure-lsp, anything else that might query the indentation system?
daveliepmann commentedon Sep 12, 2023
thanks for looking into this!
electric-indent, yes
vemv commentedon Sep 12, 2023
Nice.
IIRC you can
(setq debug-on-quit t),C-gand see what clojure-mode was doing in a given moment?If you do it enough times, you might perceive a common pattern.
vemv commentedon Sep 12, 2023
Here's a possible lead clojure-emacs/cider#3344
Apparently "electric / aggressive indentation modes" can query
cider-current-replwhich can be relatively slow, and noticeably slow if repeated enough times.Would very much appreciate if you could verify a specific cause.
vemv commentedon Sep 12, 2023
Here's a benchmark you can run for discarding/confirming that lead:
It returns 0.00005400 for me (and it successfully finds a repl - please make sure of that) - seems fast enough to be repeatedly invoked.
daveliepmann commentedon Sep 12, 2023
I think this is the right direction, because I think I just found a huge supporting clue of several parts:
cider-connected to a babashka REPL in the current buffer, indentation is fast enough but I do notice a flicker of progress % in the minibuffer and there's a noticeable subsecond lagvemv commentedon Sep 12, 2023
Thanks!
Could you please
(benchmark-elapse (cider-current-repl))for each case?Expanding on that,
(cider-current-repl)can invoke a function namedcider--sesman-friendly-session-p.Assuming a given
(cider-current-repl)call for a specific scenario is slow, please also benchmark(cider-debug-sesman-friendly-session-p)which is a special defun that exercisescider--sesman-friendly-session-p. It's sensitive to the current buffer you invoke it from (withM-:)If
(cider-debug-sesman-friendly-session-p)performs slowly, please profile it and share which specific function calls within it are to blame for the slowness.daveliepmann commentedon Sep 12, 2023
for
(benchmark-elapse (cider-current-repl)):9.2e-050.0001290.0001080.000149for
(benchmark-elapse (cider-debug-sesman-friendly-session-p)):0.0005570.0376270.0005070.09996👀profile-report
M-:,(cider-debug-sesman-friendly-session-p)vemv commentedon Sep 13, 2023
Good find!
The profiling doesn't appear to capture
cider-debug-sesman-friendly-session-p's body - I can only see smex (M-x) stuff there.I tried profiling it myself now but I can't get it to show up in the report.
I'll be happy to optimize
cider-debug-sesman-friendly-session-ponce we find what's slow in it.vemv commentedon Sep 13, 2023
Hey @daveliepmann , regardless of the profiling, I went ahead and improved that function since it was evident that it could be optimized:
clojure-emacs/cider#3463
I'd much appreciate if you can try it locally. If you use ELPA, one way is to download those two files, place them in
~/.emacs.d/elpa/cider*, remove any .elc files and restart Emacs.daveliepmann commentedon Sep 13, 2023
Thanks, I really appreciate you chasing these leads. I got those two files downloaded and running and see no change. (I confirmed they were the running code with describe-mode and some jump-to-def, though I didn't see any .elc files to delete — not sure if that could be an issue?)
I also noticed that the slowdown in the clojure-mode-but-no-CIDER-REPL only occurs when there's a cider-connect'd babashka REPL running elsewhere, not when I have a cider-jack-in'd-JVM-REPL running elsewhere with the following start-up command:
vemv commentedon Sep 13, 2023
I see!
What's the value of
(benchmark-elapse (cider-debug-sesman-friendly-session-p))for the problematic buffer?vemv commentedon Sep 13, 2023
Also, a quick way to check if the new code is being used is
M-: cider--sesman-friendly-session-calculated-atin the problematic buffer - it should have a non-nil value.daveliepmann commentedon Sep 13, 2023
0.028764
2 remaining items
vemv commentedon Sep 13, 2023
Thanks much!
I've upgraded clojure-emacs/cider#3463. Before, even though nothing was 'broken', the cache wasn't being hit.
Now it is. I have verified so with numbers: for a 'non-friendly' buffer, runtime has improved from 0.00251 to 0.0003.
daveliepmann commentedon Sep 13, 2023
I updated to the latest from that PR and profiled again; results in cpu-profiler-report2. seemed marginally faster at best
vemv commentedon Sep 13, 2023
Thanks!
I don't see a smoking gun.
Could you please perform the following?
(setq inhibit-message t)(benchmark-elapse (cider-debug-sesman-friendly-session-p))within the problematic bufferdaveliepmann commentedon Sep 13, 2023
sure
(lightly edited)
vemv commentedon Sep 13, 2023
Thanks, interesting.
What's the output of
M-: cider--sesman-friendly-session-resultwithin that buffer?daveliepmann commentedon Sep 13, 2023
(dict #<buffer *cider-repl knowuro-cljd/bb:localhost:1667(clj)*> nil)vemv commentedon Sep 13, 2023
Thanks!
Is this part
"was not determined to belong to classpath:" nil "or classpath-roots:" nilreproduced as-is?...That would mean that babashka is returning a nil classpath, which might have to do with the whole thing.
In addition, please visit the bb repl and eval both of these individually (after having reproduced the issue one more time):
What does each expr return?
daveliepmann commentedon Sep 13, 2023
Correct, that is as-is. I just elided the path on my machine.
vemv commentedon Sep 13, 2023
Thanks.
So, the process isn't holding any of the big objects to be cached. Maybe that's related to the nature of bb? Since it's an nrepl server I'd imagine it's a persistent process, but also bb is oriented towards one-off things (i.e., they run and complete very quickly) so maybe something is 'one-off' there?
That would mean a bb repl is unable to cache anything.
Does that ring a bell?
daveliepmann commentedon Sep 13, 2023
I'm not qualified to answer for bb; maybe @borkdude knows?
vemv commentedon Sep 13, 2023
The exact question is whether cider's nrepl-server process that is backed by bb is a "true" persistent server, or contrariwise something that is spawned on demand for each request.
Not sure if Michiel implemented that, but he might know!
borkdude commentedon Sep 13, 2023
The server is persistent.
cider--sesman-friendly-session-p: check for `ns-list` op availability
cider--sesman-friendly-session-p: check for `ns-list` op availability