emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tree-sitter indentation for js-mode & cc-mode


From: Yuan Fu
Subject: Re: Tree-sitter indentation for js-mode & cc-mode
Date: Fri, 28 Oct 2022 18:05:29 -0700


> On Oct 28, 2022, at 12:49 PM, Theodor Thornhill <theo@thornhill.no> wrote:
> 
> 
>>> 
>> 
>> Ok, I’m fairly certain this is due to tree-sitter reparsing after we
>> indenting each line: treesit-buffer-root-node asks for the root node
>> of the parser, which triggers a reparse, because last indent modified
>> the buffer. We are basically reparsing as many time as there are lines
>> in the buffer.
>> 
>> Indenting a similarly sized buffer where all indent are good is much
>> faster, because there is no reparse due to change to the buffer.
> 
> Yeah, that's what I was seeing as well. I think this is correct.
>> 
>> Tree-sitter indent should add an implementation for indent-for-region
>> function which precomputes indent for each line and indent lines in
>> batch. That ought to fix it. Added to TODO :-)
> 
> Hehe, sorry!

Now done. Tree-sitter’s indentation is now slightly faster than cc-mode’s. 
There are certainly still room for improvement, around 70% time are spent in 
evaluating each indentation rules. In the future we could introduce a 
preprocessor for indentation rules like the one for font-lock rules which can 
pro-compile the rules’s higher order functions. And maybe we can optimize the 
way we layout the rules slightly.

Yuan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]