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.bugs Subject: bug#60691: 29.0.60; Slow tree-sitter font-lock in ruby-ts-mode Date: Thu, 12 Jan 2023 13:58:48 -0800 Message-ID: <6F1CC7E3-E5B2-4E51-93F6-455A2D0C771E@gmail.com> References: <867cxv3dnn.fsf@mail.linkov.net> 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="38505"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 60691@debbugs.gnu.org, juri@linkov.net To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 12 22:59:20 2023 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 1pG5bT-0009tr-Tw for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 12 Jan 2023 22:59:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pG5bF-0008GM-MJ; Thu, 12 Jan 2023 16:59:05 -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 1pG5bD-0008GA-Uk for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2023 16:59: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 1pG5bC-0001sb-HO for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2023 16:59:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pG5bC-0003n3-DJ for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2023 16:59:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <867cxv3dnn.fsf@mail.linkov.net> Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Jan 2023 21:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60691 X-GNU-PR-Package: emacs Original-Received: via spool by 60691-submit@debbugs.gnu.org id=B60691.167356073814557 (code B ref 60691); Thu, 12 Jan 2023 21:59:02 +0000 Original-Received: (at 60691) by debbugs.gnu.org; 12 Jan 2023 21:58:58 +0000 Original-Received: from localhost ([127.0.0.1]:48724 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pG5b8-0003mj-1I for submit@debbugs.gnu.org; Thu, 12 Jan 2023 16:58:58 -0500 Original-Received: from mail-pj1-f43.google.com ([209.85.216.43]:45003) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pG5b5-0003mU-Kw for 60691@debbugs.gnu.org; Thu, 12 Jan 2023 16:58:56 -0500 Original-Received: by mail-pj1-f43.google.com with SMTP id o7-20020a17090a0a0700b00226c9b82c3aso22453651pjo.3 for <60691@debbugs.gnu.org>; Thu, 12 Jan 2023 13:58:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=/9woX2rdgAbZJ8bomT/4I+Ne9ZTerZyswRjNWI7oGkE=; b=TGu/eHxMPdXqGQDlTUsZu7WQJLAba4FGFePSyKV6LC76RBcKAT5zdbAxXbHTCRUH46 CF6lDPMcINyjQ1upETykht8ptQ0Mtb0QZmasa1C5z7g10lZu1+ztA3bgqus7+ZkKuo4m snnsxr/guH8E7nH9EXCx5Z7uJ/D3gIBlqEPINjyiTzMS3mhxcOIzvrvgenos0uOCPCdC qW4+JzeDnwwY5+EWiShCKQ4+xeDLnmgDw7khpvgnHTxjsC4w0eDeZXuN1nYd0ZFF7e/t J21tBp67jZFNSfWpSVGMnVu2oTP3/Rqy2f3KpCnlu1wW5YBQFCo4QeKXssNBQ+T3I/dr GGWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/9woX2rdgAbZJ8bomT/4I+Ne9ZTerZyswRjNWI7oGkE=; b=FvcxUX2tl0f9wgaX4c9EPRFFC2YJzpS2WOUHLGedqHyeOUsRQ9EJZePO2wtEYpevGU 45uSKetyLIyUjxykEuRNjAZ6UAIrAN7SsW5mf4vPtZ3aYnRcWDTmF/vxEzaeFgu0ORnV m0+4I299oooEJlSZj03dOgDpxi5E+J6jb3Cabnjv79OjGKrWuz55kwhEU9LRPOTWyLkq JzhspLkDp6FvbGnystfZ/AjTYMW3gvrOOMOr6NgTTPPIsI8VBLtOPHIUrGYM9QMZ0qzn FMpkiVsbGph4kUS5dt+ZxxBb2FLZz+4dOImXBMLDv5kKaCiuaYR3gxIFnSQU53TfYSlk Pz4w== X-Gm-Message-State: AFqh2kpkWeqPt1Yl4HPsRkprfZVJH6h86gVKSg6vYwTcDpiUdbroaX3R 615TccQ+PFHOr0PRauDUogw= X-Google-Smtp-Source: AMrXdXuz6obcOM3zRLdOo2rr7B+Y3MayZlhGofsxOm3zsumwAPCbGueVNgdmvrnpF8mf14Xqo+Q/gA== X-Received: by 2002:a17:903:2093:b0:194:4285:dfef with SMTP id d19-20020a170903209300b001944285dfefmr9954462plc.49.1673560729810; Thu, 12 Jan 2023 13:58:49 -0800 (PST) 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 a10-20020a170902ecca00b00189a7fbfd44sm12612249plh.211.2023.01.12.13.58.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jan 2023 13:58:49 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) 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:253246 Archived-At: Dmitry Gutov writes: > Yuan? Just making sure you got this message. Sorry for the delay :-) > On 10/01/2023 16:10, Dmitry Gutov wrote: >> Perhaps Yuan has some further ideas. There are some strong oddities = here: >> - Some time into debugging and repeating the benchmark again and >> again, I get the "Pure Lisp storage overflowed" message. Just once >> per Emacs session. It doesn't seem to change much, so it might be >> unimportant. That sounds like 60653. The next time you encounter it, could you record the output of M-x memory-usage and M-x memory-report?=20 >> - The profiler output looks like this: >> 18050 75% - >> font-lock-fontify-syntactically-region >> 15686 65% - treesit-font-lock-fontify-region >> 3738 15% treesit--children-covering-range-recurse >> 188 0% treesit-fontify-with-override >> - When running the benchmark for the first time in a buffer (such as >> ruby.rb), the variable treesit--font-lock-fast-mode is usually >> changed to t. In one Emacs session, after I changed it to nil and >> re-ran the benchmark, the variable stayed nil, and the benchmark ran >> much faster (like 10s vs 36s). >> In the next session, after I restarted Emacs, that didn't happen: it >> always stayed at t, even if I reset it to nil between runs. But if I >> comment out the block in treesit-font-lock-fontify-region that uses >> it >> ;; (when treesit--font-lock-fast-mode >> ;; (setq nodes (treesit--children-covering-range-recurse >> ;; (car nodes) start end (* 4 = jit-lock-chunk-size)))) >> and evaluate the defun, the benchmark runs much faster again: 11s. >> (But then I brought it all back, and re-ran the tests, and the >> variable stayed nil that time around; to sum up: the way it's turned >> on is unstable.) >> Should treesit--font-lock-fast-mode be locally bound inside that >> function, so that it's reset between chunks? Or maybe the condition >> for its enabling should be tweaked? E.g. I don't think there are any >> particularly large or deep nodes in ruby.rb's parse tree. It's a >> very shallow file. Yeah that is a not-very-clever hack. I=E2=80=99ve got an idea: I can add = a C function that checks the maximum depth of a parse tree and the maximum node span, and turn on the fast-mode if the depth is too large or a node is too wide. And we do that check once before doing any fontification. I=E2=80=99ll report back once I add it. Yuan