all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Theodor Thornhill <theo@thornhill.no>
Cc: emacs-devel <emacs-devel@gnu.org>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Tree-sitter indentation for js-mode & cc-mode
Date: Fri, 28 Oct 2022 18:05:29 -0700	[thread overview]
Message-ID: <EC0B7F2C-D990-474A-8289-5AC8755B9239@gmail.com> (raw)
In-Reply-To: <87wn8jd8zp.fsf@thornhill.no>



> 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	other threads:[~2022-10-29  1:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27  1:43 Tree-sitter indentation for js-mode & cc-mode Yuan Fu
2022-10-27  9:11 ` Theodor Thornhill
2022-10-27  9:28   ` Theodor Thornhill
2022-10-27  9:58     ` Theodor Thornhill
2022-10-27 15:21   ` Yuan Fu
2022-10-27 18:36     ` Theodor Thornhill
2022-10-28  8:15       ` Yuan Fu
2022-10-28  8:59         ` Theodor Thornhill
2022-10-28  9:10         ` Theodor Thornhill
2022-10-28 19:43           ` Yuan Fu
2022-10-28 19:49             ` Theodor Thornhill
2022-10-29  1:05               ` Yuan Fu [this message]
2022-10-29  5:53             ` Eli Zaretskii
2022-10-29  6:54               ` Yuan Fu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EC0B7F2C-D990-474A-8289-5AC8755B9239@gmail.com \
    --to=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=theo@thornhill.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.