Repository navigation
Speed up indentation of forms with many children - #174
Merged
Merged
Conversation
Getting the field of a node walks the siblings before it, and clojure-ts--value-position got the field of every sibling before a line, so the time to indent a form grew with the cube of its length: indent-region took 13 seconds on a comment form holding 400 functions, and 4.7 on cljs/core.cljs. In a collection, the field follows from the node's type, except for the prefix of a namespaced map, which comes right after its #.
Finding the indentation rule counted the forms before a line at every level it climbed, though only a rule for a given argument needs the count, and only to tell whether the line is at that argument. A block rule likewise only compares it with its number of special arguments. In a form with many children, each line paid for counting all the forms before it.
clojure-ts--anchor-parent-opening-paren searches the parent for its paren, and the search tests the parent itself first, so getting the node's text copied the whole form for every line in its body.
bbatsov
force-pushed
the
faster-value-position
branch
from
November 7, 2026 08:53
2dacc19 to
ee879d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Indenting a form with many children slowed down with the cube of its length, mostly because Emacs finds a node's field by walking the siblings before it: a
commentform holding 400 functions took 13 seconds, andcljs/core.cljs4.7 (now 0.3 and 0.7). Telling value children apart by their type gives the same answer as the field for every child of a collection across 928 Clojure files, and the sameindent-regionoutput.