From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#60691: 29.0.60; Slow tree-sitter font-lock in ruby-ts-mode Date: Fri, 13 Jan 2023 01:40:56 +0200 Message-ID: <0ba1ca9c-78e3-f961-787e-4758beaa3c5b@yandex.ru> References: <867cxv3dnn.fsf@mail.linkov.net> <6F1CC7E3-E5B2-4E51-93F6-455A2D0C771E@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16614"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Cc: 60691@debbugs.gnu.org, juri@linkov.net To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 13 00:42:19 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 1pG7D9-0004Cf-4X for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 13 Jan 2023 00:42:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pG7Ct-000744-UY; Thu, 12 Jan 2023 18:42:03 -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 1pG7Cs-00073q-DC for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2023 18:42:02 -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 1pG7Cr-0001sy-Tq for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2023 18:42:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pG7Cr-0006ti-J8 for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2023 18:42:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Jan 2023 23:42:01 +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.167356686726418 (code B ref 60691); Thu, 12 Jan 2023 23:42:01 +0000 Original-Received: (at 60691) by debbugs.gnu.org; 12 Jan 2023 23:41:07 +0000 Original-Received: from localhost ([127.0.0.1]:48861 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pG7Bz-0006rz-8u for submit@debbugs.gnu.org; Thu, 12 Jan 2023 18:41:07 -0500 Original-Received: from mail-ej1-f47.google.com ([209.85.218.47]:43983) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pG7Bx-0006rO-7J for 60691@debbugs.gnu.org; Thu, 12 Jan 2023 18:41:06 -0500 Original-Received: by mail-ej1-f47.google.com with SMTP id hw16so36701651ejc.10 for <60691@debbugs.gnu.org>; Thu, 12 Jan 2023 15:41:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=G9PWF+FHoTG5EJvb7lvyvAbPqIQaMs0RZYu1eiR7/s0=; b=aiQ7w+/uAGckaH2duHMDgKSvzwZ5C9XZ55W331sgtGM1UThoYa6nO+R2q0+KjQhjO3 Eq3a4zS3JFVf263Y+adKKDr6DCw8oBzlr2Qr+LIqqdLHhscy4HcCHNcrdfNVdhoG/OdK YgAZAJMmyDKldeKwQR4EjPrlMKHO7Ly4/YyvW0x26QoVRgtaDRslIaEgKxd7VwulmYq0 L5XoSBqC+IYeAT8ENhxe60k6kPXFr7Vq2DzNAPM1s/CA1Z0cozmdAVKEyu43+Qe5Jq8K 1kvHtN6WGGSA19yr14utPDPjCZqx9hYGSKltxQ6D4fWD7Z304NP4lncwdndteMXmoP9R 9G7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=G9PWF+FHoTG5EJvb7lvyvAbPqIQaMs0RZYu1eiR7/s0=; b=v6MRcz4GjazDZKa8sl3ihcD+GG/iBhmvSU5uK2HGBUCrsvvWZ6qPfr6ECSnwhGw6qr fF3+VXIDXLhXYVWAyVyhu+YvTcn2CSzxTFpoC1I6cqjllJCkGEnvM7M6gbtyoyz9bGGH ndQSRIg3HpyM8OrKnKe3QvxQOi2Z50l84N0m50kxxBJ3jkjowv3DcwAPZ7myMUZ8nrY6 rRUVgGHEtjZMMHQ3Zd6uR3EINsCzyw+duDFf984QrcEwFdySye6enqbfx4X90Byxm09U h8Bf5XvRGSBInXlXdYPnOHK91dsuov0i1CBQDco1nRSsqReylxNJciVR2D1hBM/ok0G8 PU7Q== X-Gm-Message-State: AFqh2kpiwdNAdhhXlidj6kaBEjUvCoDKo2FIE5WfohFrpF7MWWYSXE6o l1MzT6uQWQfAMBZnAmUlhBc= X-Google-Smtp-Source: AMrXdXsYW9Hxb41UNyatlRxxpijViRNQ6fbwiVaFzCthONJEMsK+HVANLJhLuB8SC1IWjVd6H1SKgQ== X-Received: by 2002:a17:907:a70b:b0:7c1:98d:a8a3 with SMTP id vw11-20020a170907a70b00b007c1098da8a3mr60271563ejc.7.1673566859131; Thu, 12 Jan 2023 15:40:59 -0800 (PST) Original-Received: from [192.168.0.2] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id d9-20020a1709063ec900b0084c2065b388sm7853479ejj.128.2023.01.12.15.40.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Jan 2023 15:40:58 -0800 (PST) Content-Language: en-US In-Reply-To: <6F1CC7E3-E5B2-4E51-93F6-455A2D0C771E@gmail.com> 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:253250 Archived-At: On 12/01/2023 23:58, Yuan Fu wrote: > > 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? Managed to reproduce this after running the test in a couple of different files. But 'M-x memory-usage' says no such command, and 'M-x memory-report' ends up with this error: Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil) memory-report--gc-elem(nil strings) memory-report--garbage-collect() memory-report() funcall-interactively(memory-report) #(memory-report record nil) apply(# memory-report (record nil)) call-interactively@ido-cr+-record-current-command(# memory-report record nil) apply(call-interactively@ido-cr+-record-current-command # (memory-report record nil)) call-interactively(memory-report record nil) command-execute(memory-report record) execute-extended-command(nil "memory-report" nil) funcall-interactively(execute-extended-command nil "memory-report" nil) #(execute-extended-command nil nil) apply(# execute-extended-command (nil nil)) call-interactively@ido-cr+-record-current-command(# execute-extended-command nil nil) apply(call-interactively@ido-cr+-record-current-command # (execute-extended-command nil nil)) call-interactively(execute-extended-command nil nil) command-execute(execute-extended-command) garbage-collect's docstring says: However, if there was overflow in pure space, and Emacs was dumped using the "unexec" method, ‘garbage-collect’ returns nil, because real GC can’t be done. I don't know if my Emacs was dumped using "unexec", though. ./configure says I'm using pdumper. In case that matters, I'm testing the emacs-29 branch. >>> - 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’ve 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’ll report back once I add it. Thanks! And if the check can be fast enough, we could probably do it in the beginning of fontifying every chunk.