Description
clojure-mode
is exceptionally slow when using aggressive-indent, especially in larger buffers. Emacs becomes so slow that it starts losing letters that are being typed in.
I'm not sure where to actually file this, as the problem is at the intersection of aggressive-indent, clojure-mode and cider — but I figured this is the best place to start.
I used the profiler to hunt for the problem and here is the result:
- aggressive-indent--indent-if-changed 1714 47%
- apply 1697 47%
- aggressive-indent--softly-indent-defun 1697 47%
- aggressive-indent-indent-defun 1648 45%
- indent-region 1647 45%
- clojure-indent-region 1647 45%
- indent-region 1647 45%
- indent-region-line-by-line 1646 45%
- indent-according-to-mode 1644 45%
- clojure-indent-line 1643 45%
- lisp-indent-line 1532 42%
- calculate-lisp-indent 1381 38%
- clojure-indent-function 1364 37%
- clojure--find-indent-spec 1300 36%
- clojure--find-indent-spec-backtracking 1299 36%
- clojure--get-indent-method 969 26%
- cider--get-symbol-indent 967 26%
- cider-current-ns 951 26%
- clojure-find-ns 950 26%
- up-list 828 22%
+ syntax-ppss 233 6%
The problem seems to be that aggressive-indent ends up calling clojure-indent-function
after every typed character. This in turn eventually needs to call clojure-find-ns
, which is very slow (I guess nobody expected that this function would need to be fast).
I am not sure what the best solution would be. I know an easy workaround is "do not use aggressive-indent". But perhaps clojure-find-ns
can be made faster? Or perhaps it isn't necessary to call it so often?
Environment & Version information
clojure-mode version information
clojure-mode (version 5.7.0)
Emacs version
26.1
Operating system
Mac OS X