Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indent very slow #606

Open
lgrapenthin opened this issue Nov 26, 2021 · 6 comments
Open

Indent very slow #606

lgrapenthin opened this issue Nov 26, 2021 · 6 comments

Comments

@lgrapenthin
Copy link

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

@bbatsov
Copy link
Member

bbatsov commented Nov 26, 2021

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.

@bbatsov
Copy link
Member

bbatsov commented Nov 26, 2021

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.

@lgrapenthin
Copy link
Author

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

@bbatsov
Copy link
Member

bbatsov commented Dec 18, 2021

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.

@lgrapenthin
Copy link
Author

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.

@bbatsov
Copy link
Member

bbatsov commented Dec 20, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants