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: Sun, 20 Nov 2022 20:54:05 +0100 Message-ID: <87k03pwgf6.fsf@thornhill.no> References: <83v8n94ij9.fsf@gnu.org> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38944"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu To: eliz@gnu.org, 59415@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 20 20:55:21 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 1owqPQ-0009xM-JN for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Nov 2022 20:55:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1owqPC-0001fc-0F; Sun, 20 Nov 2022 14:55:06 -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 1owqP9-0001fN-2e for bug-gnu-emacs@gnu.org; Sun, 20 Nov 2022 14:55:03 -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 1owqP8-00019D-C1 for bug-gnu-emacs@gnu.org; Sun, 20 Nov 2022 14:55:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1owqP8-0000Dk-2A for bug-gnu-emacs@gnu.org; Sun, 20 Nov 2022 14:55: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: Sun, 20 Nov 2022 19:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59415 X-GNU-PR-Package: emacs X-Debbugs-Original-To: Eli Zaretskii , bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.1668974067805 (code B ref -1); Sun, 20 Nov 2022 19:55:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Nov 2022 19:54:27 +0000 Original-Received: from localhost ([127.0.0.1]:44702 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owqOY-0000Cv-M0 for submit@debbugs.gnu.org; Sun, 20 Nov 2022 14:54:27 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:38164) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owqOS-0000Ch-Aa for submit@debbugs.gnu.org; Sun, 20 Nov 2022 14:54:24 -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 1owqOS-0001dU-4z for bug-gnu-emacs@gnu.org; Sun, 20 Nov 2022 14:54:20 -0500 Original-Received: from out2.migadu.com ([2001:41d0:2:aacc::]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1owqOP-00014s-4y; Sun, 20 Nov 2022 14:54:19 -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=1668974052; 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: in-reply-to:in-reply-to:references:references; bh=kLQijqgzTCmgqU/aX9VJuKHb+Vg1Cr4eZtGdpdTg2xs=; b=kUkc49LG/Xk45lTCwkGQH2dGg5MPcRm4rpl/AgOXMxoJGjOigRqCFix6xVEiGeiszfTa0G 4dNnjgZF2r+NzHkMFT74bIH1TVq3nBl41ECa9j5LUqVmWyBwwuxzW7MWqrRPVyYc6jhT7k LsM0kT3w6I+XfuL3dz3YibCrtydA6YRWvJFNcEnwouARIpiqhMvOrjkx2EoNImrADFHqUl T4hM3cHve3pqLkfYiC9ADnevFyy2/FEMkfj4oWxdWDNFFqGYmlLaBtanFxKCiM6L60pxtJ mFX+ho6gAXFktQmp55yD5CKyYYkddtcsJM9VUqBMgDAL/oD51OFhtJ3rdlLjmQ== In-Reply-To: <83v8n94ij9.fsf@gnu.org> X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:2:aacc::; envelope-from=theo@thornhill.no; helo=out2.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:248467 Archived-At: Hi and thanks for cc. > > Observe that fontifications stop at this line for some reason. > Fontification reappears on line 209271. Maybe it's because of the many > braces that appear in warning face? Why does TS think there are syntax > errors here? The C++ TS parser doesn't have that problem, btw. > It seems the c parser definitely can't handle what it's seeing. > P.S. Btw, isn't the treesit-max-buffer-size limit too low? 4 MiB? > It might be! IIRC treesit uses 10x the buffer size to store the ast, so it'll be some more memory usage. I'll do some more digging, but in the meantime I attach this profiler report that shows font-locking as the culprit: In this profile I followed your repro, and did some more movement around the buffer after. This isn't from emacs -Q, but I believe the results will be just the same, considering where the slowness seems to be 16695 85% - redisplay_internal (C function) 16695 85% - jit-lock-function 16695 85% - jit-lock-fontify-now 16695 85% - jit-lock--run-functions 16695 85% - run-hook-wrapped 16695 85% - # 16695 85% - font-lock-fontify-region 16695 85% - font-lock-default-fontify-region 16679 84% - treesit-font-lock-fontify-region 2080 10% treesit-buffer-root-node 2689 13% - command-execute 2689 13% - call-interactively 2380 12% - funcall-interactively 1576 8% - scroll-up-command 1525 7% - scroll-up 1525 7% - jit-lock-function 1525 7% - jit-lock-fontify-now 1525 7% - jit-lock--run-functions 1525 7% - run-hook-wrapped 1525 7% - # 1525 7% - font-lock-fontify-region 1525 7% - font-lock-default-fontify-region 1525 7% treesit-font-lock-fontify-region 633 3% - end-of-buffer 628 3% - recenter 628 3% - jit-lock-function 628 3% - jit-lock-fontify-now 628 3% - jit-lock--run-functions 628 3% - run-hook-wrapped 628 3% - # 628 3% - font-lock-fontify-region 628 3% - font-lock-default-fontify-region 628 3% treesit-font-lock-fontify-region 5 0% push-mark 128 0% - project-find-file 128 0% - project-find-file-in 86 0% - project--read-file-cpd-relative 86 0% - project--completing-read-strict 86 0% - completing-read 86 0% - completing-read-default 86 0% - apply 86 0% - vertico--advice 86 0% - apply 86 0% - # 79 0% - read-from-minibuffer 37 0% - vertico--exhibit 26 0% - vertico--update 22 0% redisplay 4 0% - vertico--recompute 4 0% - vertico-sort-history-length-alpha 4 0% - mapcan 4 0% - # 4 0% sort 11 0% - vertico--display-candidates 11 0% vertico--resize-window 15 0% - timer-event-handler 10 0% - apply 7 0% - battery-update-handler 7 0% - sit-for 7 0% - redisplay 7 0% redisplay_internal (C function) 3 0% # 2 0% - internal-timer-start-idle 2 0% timerp 2 0% - command-execute 2 0% - call-interactively 2 0% - funcall-interactively 2 0% - vertico-exit 2 0% - vertico--match-p 2 0% - test-completion 2 0% - # 2 0% complete-with-action 27 0% - find-file 27 0% - find-file-noselect 24 0% - find-file-noselect-1 4 0% - insert-file-contents 4 0% - set-auto-coding 4 0% - find-auto-coding 4 0% sgml-html-meta-auto-coding-function 4 0% - after-find-file 4 0% - normal-mode 4 0% - set-auto-mode 4 0% - set-auto-mode--apply-alist 4 0% - set-auto-mode-0 4 0% - c-ts-mode 4 0% treesit-ready-p 3 0% - find-buffer-visiting 3 0% abbreviate-file-name 15 0% - project-files 15 0% - apply 15 0% - # 15 0% - mapcan 15 0% - # 15 0% - project--vc-list-files 11 0% - apply 11 0% - vc-git--run-command-string 11 0% - # 11 0% - kill-buffer 11 0% - replace-buffer-in-windows 11 0% - unrecord-window-buffer 11 0% assq-delete-all 4 0% split-string 5 0% - next-line 5 0% - line-move 5 0% line-move-visual 4 0% - execute-extended-command 4 0% - command-execute 4 0% - call-interactively 4 0% - funcall-interactively 4 0% profiler-stop 2 0% - digit-argument 2 0% - universal-argument--mode 2 0% set-transient-map 309 1% - byte-code 309 1% - read-extended-command 309 1% - read-extended-command-1 309 1% - completing-read 309 1% - completing-read-default 309 1% - apply 309 1% - vertico--advice 309 1% - apply 309 1% - # 276 1% - read-from-minibuffer 253 1% - vertico--exhibit 249 1% - vertico--update 240 1% - vertico--recompute 236 1% - vertico--all-completions 236 1% - apply 236 1% - completion-all-completions 236 1% - completion--nth-completion 236 1% - completion--some 236 1% - # 163 0% - completion-basic-all-completions 163 0% - completion-pcm--all-completions 163 0% - all-completions 163 0% - # 163 0% - complete-with-action 4 0% - all-completions 4 0% - # 4 0% # 73 0% - completion-substring-all-completions 73 0% - completion-substring--all-completions 64 0% - completion-pcm--all-completions 64 0% - all-completions 64 0% - # 64 0% complete-with-action 4 0% - test-completion 4 0% - # 4 0% complete-with-action 7 0% redisplay 4 0% - vertico--display-candidates 4 0% vertico--resize-window 4 0% - redisplay_internal (C function) 4 0% - eval 4 0% unless 201 1% + timer-event-handler 50 0% + ... 4 0% set-message-functions