clojure-emacs / clojure-mode

Emacs support for the Clojure(Script) programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indent very slow

lgrapenthin opened this issue · comments

Use the template below when reporting bugs. Please, make sure that
you're running the latest stable clojure-mode and that the problem you're reporting
hasn't been reported (and potentially fixed) already.

Please, remove all of the placeholder text (the one in italics) in your final report!

Expected behavior

Fast

Actual behavior

Slow

Steps to reproduce the problem

Indent about a 1000 lines with little nesting.

After using the profiler, I determined that I can set clojure-use-backtracking-indent to nil and get a nice speedup of about 90%. I don't know what it does ("When non-nil, enable context sensitive indentation."??) - Still its too slow and takes more than a second. My machine is not the fastest, but 2 Ghz should suffice to indent a few pages of text in less than a second in a text editor.

This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.

Environment & Version information

clojure-mode version

5.13.0
Include here the version string displayed by M-x clojure-mode-display-version. Here's an example:

clojure-mode (version 5.2.0)

Emacs version

E.g. 24.5 (use C-h C-a to see it)
26.3

Operating system

E.g. Windows 10

After using the profiler, I determined that I can set clojure-use-backtracking-indent to nil and get a nice speedup of about 90%. I don't know what it does ("When non-nil, enable context sensitive indentation."??)

This basically means we try harder to find an indentation spec for the current context (where your cursor is). As you can imagine that's slower, but yield better results in some case. See:

(defun clojure--find-indent-spec ()
  "Return the indent spec that applies to current sexp.
If `clojure-use-backtracking-indent' is non-nil, also do
backtracking up to a higher-level sexp in order to find the
spec."
  (if clojure-use-backtracking-indent
      (save-excursion
        (clojure--find-indent-spec-backtracking))
    (let ((function (thing-at-point 'symbol)))
      (clojure--get-indent-method function))))

I'm open ideas how to make the indentation work faster.

If someone is using fixed indentation (always-indent) then I think they can safely set this to nil, as they don't need indentation specs.

@bbatsov It appears that when I turn it off, defprotocol and reify get indented incorrectly. Is this intended?

Yeah, that's expected. Otherwise we wouldn't need the complicated backtracking indent. :-) I'll add some note to the docs, so it's clearer.

Yeah, that's expected. Otherwise we wouldn't need the complicated backtracking indent. :-) I'll add some note to the docs, so it's clearer.

But I'm talking about indenting the form as a whole, i. e. not from "where your cursor is" or having to look at a higher nesting level.

Yeah, I understand this, but such forms are essentially composed of several definitions and can't be indented directly without extra work. At least not with the current state of the indentation engine.