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: Fri, 20 Jan 2023 14:24:28 -0800 Message-ID: <90D70081-4A27-4219-93C3-240D35F29711@gmail.com> References: <867cxv3dnn.fsf@mail.linkov.net> <4b75a1e5-ace9-2312-54f7-c1de9c798d9c@yandex.ru> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.300.101.1.3\)) 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="32546"; 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 Fri Jan 20 23:25:17 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 1pIzoy-0008KD-Uc for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Jan 2023 23:25:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIzon-0008Uy-4M; Fri, 20 Jan 2023 17:25: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 1pIzom-0008Un-0g for bug-gnu-emacs@gnu.org; Fri, 20 Jan 2023 17:25:04 -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 1pIzok-0001FK-N5 for bug-gnu-emacs@gnu.org; Fri, 20 Jan 2023 17:25:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pIzok-0003PR-32 for bug-gnu-emacs@gnu.org; Fri, 20 Jan 2023 17:25:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Jan 2023 22:25: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.167425348713074 (code B ref 60691); Fri, 20 Jan 2023 22:25:02 +0000 Original-Received: (at 60691) by debbugs.gnu.org; 20 Jan 2023 22:24:47 +0000 Original-Received: from localhost ([127.0.0.1]:47424 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIzoV-0003Oo-Df for submit@debbugs.gnu.org; Fri, 20 Jan 2023 17:24:47 -0500 Original-Received: from mail-pj1-f42.google.com ([209.85.216.42]:43982) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIzoT-0003OU-Pc for 60691@debbugs.gnu.org; Fri, 20 Jan 2023 17:24:46 -0500 Original-Received: by mail-pj1-f42.google.com with SMTP id m3-20020a17090a414300b00229ef93c5b0so5535524pjg.2 for <60691@debbugs.gnu.org>; Fri, 20 Jan 2023 14:24:45 -0800 (PST) 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=yBRL9SkyjI0Jh0dvzLjzRWSjHDz+ERBBGBnWrhbSQQU=; b=qh7kIcMM//Jpe6K4HABzbQg70334yvaWMsQoTJ415s3VWxQfMSQyK6rBz6gjaw0dV7 N58yki7m3Lp0h0LSlf7aH/H/blrEeaqNMEBw+0V4iRVwK0sus92XMr7boZI1XxNqgA2m tCS2/W5Go1f5+dWU7dUAJ7A1cA/ckpy2X6Ui3oKiZVdnfhV2FWVFuzbOVjruiDNFyKVn 0310T0NYJtV4JgWryrmr5er/LSjRZJQi5V6hVh4oxXTvMLHeaul6gIYJYmkE0yZdsk+v wp7AUTA2SETN/aqgiZRqC4Jld4ItHoH6T7v+IBpwflsX4vJ0yna1oMzh78YSD4XIhRv8 CW2Q== 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=yBRL9SkyjI0Jh0dvzLjzRWSjHDz+ERBBGBnWrhbSQQU=; b=wKJ9+rSJ2J+eGSDhSzcRHRR2WoqO9DT27ijSe1LPcBeDWSLwFBzbVRS3gN+psexoWa y66H1qEQ5FzY/0RqQ0nT8bZ3/gH4kXCxjSwos7jO2JjGMQNAb80RwsdliYcekUuDihiC DXNVhZhUL9Kb7ra4FYzqfmBtQrZ0e/ixUafwokIWFxWm8IWWPc2uIn5vwDyjPZUO+yen dQ8XLHq8U53vqaK+VjFk+eTD8jF/eL0FovHmqiLyVJayCX/1uvHJLHp/vbfEGGeA8Pj1 JsxNBs5Cv/Npsm5Y6NS+FIAi7KJmMRHK2HE5TX9iPrvJCf0yHWvHkY31Qcc+R1WqubBq PmXQ== X-Gm-Message-State: AFqh2krNwzNfnaGuNqQuiVYAnfn+2d90Znf1ikLYlyYOqXOC4uWC5Det gS3p/G9vAgxr4vPIVsIM4UE= X-Google-Smtp-Source: AMrXdXvQHBQ20KolP43LmU0diXci8PctW0EwUNX6kedU1HwHooS2U6Jfevy31brXPC1nOSreutdB3Q== X-Received: by 2002:a17:903:40cc:b0:194:3f40:69b7 with SMTP id t12-20020a17090340cc00b001943f4069b7mr16455709pld.63.1674253480148; Fri, 20 Jan 2023 14:24:40 -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 z20-20020a170903409400b001933b4b1a49sm22014213plc.183.2023.01.20.14.24.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jan 2023 14:24:39 -0800 (PST) In-Reply-To: <4b75a1e5-ace9-2312-54f7-c1de9c798d9c@yandex.ru> X-Mailer: Apple Mail (2.3731.300.101.1.3) 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:253811 Archived-At: > On Jan 19, 2023, at 10:28 AM, Dmitry Gutov wrote: >=20 > Hi Yuan, >=20 > On 18/01/2023 08:50, Yuan Fu wrote: >>>>> 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. >>>=20 >>> 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. >>>=20 >>> I=E2=80=99ll report back once I add it. >> I wrote that function. But I didn=E2=80=99t end up using it. Instead = I added a >> "grace count", so that the query time has to be longer than the >> threshold 5 times before we switch on the fast mode instead of 1. >> My main worry is that simply looking at the parse tree would not = catch >> all the case where there will be expensive queries. >=20 > That might be true, but a criterion that doesn't specify conditions = exactly can give no guarantee against false positives. The condition is =E2=80=9Cquery is (consistently) slow=E2=80=9D, = that=E2=80=99s why I thought measuring the time is the most direct way. >=20 >> Could you try the latest commit and see if the fast mode still = switches >> on when it shouldn=E2=80=99t? >=20 > At first it seemed to help, but then I switched the major mode a = couple more times, and ran the benchmark twice more, and the "fast mode" = switched on again. >=20 > Which seems to make sense: there is no resetting the counter, right? >=20 > So if previously it happened once somehow during a certain scenario, = now I have to repeat the same scenario 4 times, and the condition is = met. I was hoping that the scenario only happen once, oh well :-) I=E2=80=99ll = change the decision based on analyzing the tree=E2=80=99s dimension: too = deep or too wide activates the fast mode. Let=E2=80=99s see how it = works. Yuan