From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#60691: 29.0.60; Slow tree-sitter font-lock in ruby-ts-mode Date: Tue, 10 Jan 2023 10:10:53 +0200 Organization: LINKOV.NET Message-ID: <86leman71u.fsf@mail.linkov.net> References: <867cxv3dnn.fsf@mail.linkov.net> <51ee2f6f-6e1d-eccd-f536-461d916cc94d@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5917"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: 60691@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jan 10 10:10:08 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 1pFAe0-0001N3-Il for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 10 Jan 2023 10:10:08 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pF9xM-0005p5-HH; Tue, 10 Jan 2023 03:26:04 -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 1pF9xK-0005mj-8O for bug-gnu-emacs@gnu.org; Tue, 10 Jan 2023 03:26: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 1pF9xJ-00050R-V8 for bug-gnu-emacs@gnu.org; Tue, 10 Jan 2023 03:26:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pF9xJ-0004eS-RC for bug-gnu-emacs@gnu.org; Tue, 10 Jan 2023 03:26:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 10 Jan 2023 08:26: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.167333914317832 (code B ref 60691); Tue, 10 Jan 2023 08:26:01 +0000 Original-Received: (at 60691) by debbugs.gnu.org; 10 Jan 2023 08:25:43 +0000 Original-Received: from localhost ([127.0.0.1]:38704 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pF9x1-0004dY-6d for submit@debbugs.gnu.org; Tue, 10 Jan 2023 03:25:43 -0500 Original-Received: from relay10.mail.gandi.net ([217.70.178.230]:54479) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pF9wz-0004dI-3d for 60691@debbugs.gnu.org; Tue, 10 Jan 2023 03:25:42 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id B02AD240004; Tue, 10 Jan 2023 08:25:31 +0000 (UTC) In-Reply-To: <51ee2f6f-6e1d-eccd-f536-461d916cc94d@yandex.ru> (Dmitry Gutov's message of "Tue, 10 Jan 2023 00:33:12 +0200") 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:253063 Archived-At: >> After more rules were added recently to ruby-ts--font-lock-settings, >> font-lock became slow even on very small files. Some measurements: > > If you saw a particular commit that made things slower, did you try > reverting it? What was the performance after? No particular commit, just adding more rules degrades performance gradually. >> M-: (benchmark-run 1000 (progn (font-lock-mode -1) (font-lock-mode 1) (font-lock-ensure))) >> M-x ruby-mode >> (1.3564674989999999 0 0.0) >> M-x ruby-ts-mode >> (8.349582391999999 2 6.489918534000001) > > I have tried this scenario (which, to be frank, is pretty artificial, given > that fontification is usually performed in chunks, not over the whole > buffer). > > Perhaps the results depend on a particular file. The ones I have tried > (ruby.rb and ruby-after-operator-indent.rb) show only 2x difference (or > less). The difference was in favor of ruby-mode, but given the difference > in approaches I wouldn't be surprised if ruby-ts-mode incurs a fixed > overhead somewhere. On test/lisp/progmodes/ruby-mode-resources/ruby.rb I see these numbers: ruby-mode (8.701560543000001 95 1.045961102) ruby-ts-mode (34.653148898000005 1464 16.904981779) >> This is not a problem when files are visited infrequently, but >> becomes a problem for diff-syntax fontification that wants to >> highlight simultaneously many files from git logs. >> So a temporary measure would be not to enable ruby-ts-mode >> in internal buffers: > > Is it common to try to highlight 1000 or even 100 files in one diff? 100 is rare, but tens is pretty common, so this problem affects only this specific case. >> (add-hook 'find-file-hook >> (lambda () >> (when (and (eq major-mode 'ruby-mode) >> ;; Only when not internal as from diff-syntax >> (not (string-prefix-p " " (buffer-name)))) >> (ruby-ts-mode)))) > > Have you tried similar tests with other -ts- modes? Ones with complex > font-lock rules in particular. I tried with c-ts-mode, and it's very fast. > I've tried commenting out different rules in ruby-ts--font-lock-settings, > but none of them seem to have particularly outsides impact. Performance > seems, roughly, inversely proportional to the number of separate > "features". Indeed, this is what I see - no particular rule, only their number affects performance. > And if all ts modes turn out to have this problem, perhaps the place to > improve this is inside some common code. I noticed that while most library files are small, e.g. libtree-sitter-c.so is 401,528 bytes, libtree-sitter-ruby.so is 2,130,616 bytes that means that it has more complex logic that might explain its performance. In this case, when nothing could be done to improve performance, please close this request.