From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#59415: 29.0.50; [feature/tree-sitter] c-ts-mode fails to fontify a portion of a large C file Date: Mon, 21 Nov 2022 12:00:37 +0100 Message-ID: <87fsec8td6.fsf@thornhill.no> References: <83v8n94ij9.fsf@gnu.org> <87k03pwgf6.fsf@thornhill.no> <83h6yt4c12.fsf@gnu.org> <87v8n9qscd.fsf@thornhill.no> <87pmdhqqni.fsf@thornhill.no> <87tu2tthmr.fsf@thornhill.no> Reply-To: Theodor Thornhill Mime-Version: 1.0 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="20774"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 59415@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 21 12:01:25 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1ox4YG-0005En-NL for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Nov 2022 12:01:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox4Y8-0000rl-NM; Mon, 21 Nov 2022 06:01:16 -0500 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 1ox4Xw-0000pu-5h for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 06:01:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ox4Xu-0006Mm-9c for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 06:01:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ox4Xu-0000hp-5L for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 06:01:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Nov 2022 11:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59415 X-GNU-PR-Package: emacs Original-Received: via spool by 59415-submit@debbugs.gnu.org id=B59415.16690284502682 (code B ref 59415); Mon, 21 Nov 2022 11:01:02 +0000 Original-Received: (at 59415) by debbugs.gnu.org; 21 Nov 2022 11:00:50 +0000 Original-Received: from localhost ([127.0.0.1]:45546 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ox4Xh-0000hB-KO for submit@debbugs.gnu.org; Mon, 21 Nov 2022 06:00:49 -0500 Original-Received: from out0.migadu.com ([94.23.1.103]:63997) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ox4Xf-0000h2-CM for 59415@debbugs.gnu.org; Mon, 21 Nov 2022 06:00:48 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1669028445; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mLmKOtaSx9Q8rfLSdruyl0e/5XtuV1qq6bxeZdciBjI=; b=D4a/TTIPcdiAontrvtzRPidXKoYRXOxw4WlT2MP0NFBhlQ4sU/RhTXsJ+zqD6m92YD1cdf 2/+q6wfOHk7FhhMyyn6Lp0sIg4I3ahmUJvRanMyctdoyrSkiK5vxAfK8OHuCabUJWmPyVx T3yIcGK96g9He1sjY6ob6ddIcNsd9JukCWtboawhMvR6pGQlto75xROKGifNg732OK4Kmx Yk0A7L9syNGBeVcecYMPYQXiGKfczhgkq867ZoxX0WOc7/AJ0xU1M8Cx84CUNmZjUvcbFV RXIhs37h0Nn8+sPXuHbfLUB5dLNCLrZxPQggV/p+gkpyHnfZR+3iA+uouaDBoQ== In-Reply-To: X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:248513 Archived-At: Yuan Fu writes: >> On Nov 20, 2022, at 1:56 PM, Theodor Thornhill via Bug reports for GNU E= macs, the Swiss army knife of text editors wrote: >>=20 >>>>=20 >>>> I appreciate the explanation. I think getting the root is a bit >>>> excessive. I got the same results as you in the capture. Maybe reuse >>>> the treesit-defun-type-regexp, and default to root if none found? >>>=20 >>> I tried the "top-level node=E2=80=9D approach, and it didn=E2=80=99t he= lp in >>> package-rrc.c: the top-level node (a function definition) is still too >>> large (spans 7680306-9936062). Since the case I described in the >>> comment against using treesit-node-on is the exception rather than the >>> norm, maybe we can go the other way around: use treesit-node-on first, >>> and if the node seems too small (by some heuristic), enlarge it to >>> some degree. >>>=20 >>=20 >> Makes sense! > > I pushed a change that uses treesit-node-on. Now scrolling in most > parts of the buffer is pretty fast. Scrolling around 194770 is still > laggy, because the node we get from treesit-node-on is still too > large. I tried some heuristics but they didn=E2=80=99t work very well, IMO > because tree-sitter couldn=E2=80=99t parse that part of the code very > well. The code should observe a structure like {{}, {}, {}, {}, {}, =E2= =80=A6} > where there are tens thousands of inner brackets, so ideally we only > need to grab the {}=E2=80=99s in the region we want to fontify. But > tree-sitter seems to understand it in some weird structure and we > still end up with very large nodes, which is far larger than the > region we want to fontify and is slow to query. > > I=E2=80=99ll try to improve it further in the future, but for now I think= it=E2=80=99s > good enough (because in most cases fontification is pretty fast). > > Also I think we should probably disable fontifying errors in C. C=E2=80= =99s > macros just create too much errors. Good job. I ran this in both c-ts-mode and c-mode on the same file: (defun scroll-up-benchmark () (interactive) (let ((oldgc gcs-done) (oldtime (float-time))) (condition-case nil (while t (scroll-up) (redisplay)) (error (message "GCs: %d Elapsed time: %f seconds" (- gcs-done oldgc) (- (float-time) oldtime)))))) c-ts-mode: GCs: 87 Elapsed time: 135.700742 seconds c-mode: GCs: 224 Elapsed time: 133.329396 seconds Font locking seems correct too. Theo