From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter indentation for js-mode & cc-mode Date: Fri, 28 Oct 2022 18:05:29 -0700 Message-ID: References: <9AF8BFDC-C9A2-4AE5-A8D2-E6AA05DA3C91@gmail.com> <87k04lljh6.fsf@thornhill.no> <541CF451-6FAC-4531-A8AF-8C86FBB9D40B@thornhill.no> <425E0075-3F44-4832-BA2E-61E7D0A26FF4@gmail.com> <87mt9ggvph.fsf@thornhill.no> <89721927-13CE-4A65-944C-0DC924127373@gmail.com> <87wn8jd8zp.fsf@thornhill.no> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18289"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel , Stefan Monnier To: Theodor Thornhill Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Oct 29 03:06:36 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ooaJ1-0004ZP-RF for ged-emacs-devel@m.gmane-mx.org; Sat, 29 Oct 2022 03:06:35 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooaI6-00054Q-HG; Fri, 28 Oct 2022 21:05:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooaI3-00054D-3u for emacs-devel@gnu.org; Fri, 28 Oct 2022 21:05:35 -0400 Original-Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ooaI1-0003D6-EQ for emacs-devel@gnu.org; Fri, 28 Oct 2022 21:05:34 -0400 Original-Received: by mail-pl1-x62f.google.com with SMTP id f23so6240927plr.6 for ; Fri, 28 Oct 2022 18:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6ABj4poz0OFx5PvCQcKBGnrm/p9fJzcZHNn8Il4YbCI=; b=Hx/zvNTEUoo2rejXXDdeDW+ZQ9i/kmZFT5BMFMnm/+kvjUi0dcTtEYeWDik6Qk9Mdo Me8CGT+l4VGiomEeFGyUjK1m3YhfZgNmiAsWmR5W5Xyahceoo13b3c0NOvJkYq8PEygD MI3kfQxjWDYU+6PKxNy+JUAkkZFcJxIxIV2VmhunWxEq5LbfHl27gZ6inoMVPivz15kV F2OTlHcMtncIXBvWL8KpkG3rIe5vuO9rMJLV2GoTpLLiRIlgkUWEzjq0sgqQwKfuklpI K1i4CQr+yJy3nwY/J1PeJoeUbxp6oNHMP2nXGUEdqI3BlOh/3h9s4ML2tDLM79SR4Xf5 X9KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ABj4poz0OFx5PvCQcKBGnrm/p9fJzcZHNn8Il4YbCI=; b=qvpKpF+XSDdwSP9RfIahX4o2FBJsYJvzAdjVjv4R2uaGsPFbnQPY+L9OBDBakJnVkT JVJn3LhITV/APVNsJdEkeFdRp+GEF3WNYXVd4lw06s6a6vB1ppecBfNMNBxiXuT8u0Pm WtyflQWPhsvJwYi/luOu3jnHADXUKGclHxLWjEFW0T4qvFC8TAHmwBKSJ4uwSyk9MmUU 5HrkInt269TRNRQE8h+rVlsIxtTkutL7Ya509KxvjS8JWSup50xCORtQLXPW1hHEesZ+ 7XXFJuWBDYYbdvox+T6rgCWkINqa96ati96i1/fEBWxlizFHN6NhWI49IUZq/kNGYZ1C SJCg== X-Gm-Message-State: ACrzQf2T4VsSsLl7OjMYfdQMwMRjagqAqQ7WmouglzTvzG4Ef8gp9Czm oF8mE4yGSTB7/f8BregtnUQ= X-Google-Smtp-Source: AMsMyM6GmRR6xtN0+B5xcFO24xaIrmUoWBWvD4+Cc4VGjSSLiFMfr0OwfjGjF53gPAKb2nqSME/xkg== X-Received: by 2002:a17:90b:38c4:b0:20d:9dfa:4339 with SMTP id nn4-20020a17090b38c400b0020d9dfa4339mr20080612pjb.74.1667005531519; Fri, 28 Oct 2022 18:05:31 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id d7-20020a17090abf8700b00212e5068e17sm49951pjs.40.2022.10.28.18.05.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Oct 2022 18:05:31 -0700 (PDT) In-Reply-To: <87wn8jd8zp.fsf@thornhill.no> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=casouri@gmail.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:298706 Archived-At: > On Oct 28, 2022, at 12:49 PM, Theodor Thornhill = wrote: >=20 >=20 >>>=20 >>=20 >> Ok, I=E2=80=99m 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. >>=20 >> Indenting a similarly sized buffer where all indent are good is much >> faster, because there is no reparse due to change to the buffer. >=20 > Yeah, that's what I was seeing as well. I think this is correct. >>=20 >> 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 :-) >=20 > Hehe, sorry! Now done. Tree-sitter=E2=80=99s indentation is now slightly faster than = cc-mode=E2=80=99s. 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=E2=80=99s higher = order functions. And maybe we can optimize the way we layout the rules = slightly. Yuan=