Skip to content

Improve performance of semantic indentation by caching rules #76

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

Conversation

rrudakov
Copy link
Contributor

@rrudakov rrudakov commented Apr 9, 2025

I've noticed that reindenting big file is pretty slow, profiler report indicated that the bottleneck is the calculation of combined indentation rules from default settings and user customizations:

(seq-union (or rules clojure-ts-semantic-indent-rules)
             clojure-ts--semantic-indent-rules-defaults
             (lambda (e1 e2) (equal (car e1) (car e2))))

this is called every time we need to calculate indentation for a single line.

This PR introduces buffer local variable clojure-ts--semantic-indent-rules-cache which stores pre-calculated rules. This variable is set when clojure-ts-mode is activated and updated every time when clojure-ts-semantic-indent-rules is updated or file local variables are updated (in case when indentation rules are defined in .dir-locals.el for example.


Before submitting a PR mark the checkboxes for the items you've done (if you
think a checkbox does not apply, then leave it unchecked):

  • You've run M-x checkdoc and fixed any warnings in the code you've written.
  • You've updated the changelog (if adding/changing user-visible functionality).
  • You've updated the readme (if adding/changing user-visible functionality).

Thanks!

@rrudakov rrudakov force-pushed the feature/semantic-indentation-performance-improvements branch 2 times, most recently from d76c16f to 9dff9d1 Compare April 9, 2025 19:46
@rrudakov rrudakov force-pushed the feature/semantic-indentation-performance-improvements branch from 9dff9d1 to b57f024 Compare April 10, 2025 07:00
@rrudakov rrudakov requested a review from bbatsov April 10, 2025 07:00
@bbatsov bbatsov merged commit 897659a into clojure-emacs:main Apr 10, 2025
2 of 3 checks passed
@rrudakov rrudakov deleted the feature/semantic-indentation-performance-improvements branch April 10, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants