From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#60953: The :match predicate with large regexp in tree-sitter font-lock seems inefficient Date: Thu, 26 Jan 2023 20:24:11 +0200 Message-ID: <83sffxcfxw.fsf@gnu.org> References: <7624dddc-4600-9a03-ac8b-d3c9e0ab618c@yandex.ru> <04729838-b7d4-8a08-2b71-12536a28aebb@yandex.ru> <83wn5ag4nc.fsf@gnu.org> <01b5d074-fb12-6b1f-cbfb-5e759833b854@yandex.ru> <838rhpg57n.fsf@gnu.org> <5026D975-983F-4D18-8690-BE139C92825D@gmail.com> <83pmb1emxi.fsf@gnu.org> <6f318afc-ca71-8b7e-c822-52e6635b5718@yandex.ru> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25214"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com, 60953@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 26 19:25:37 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 1pL6wK-0006JB-9a for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Jan 2023 19:25:36 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pL6vo-0004YV-Ra; Thu, 26 Jan 2023 13:25: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 1pL6vn-0004YN-B8 for bug-gnu-emacs@gnu.org; Thu, 26 Jan 2023 13:25: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 1pL6vm-00020W-Tv for bug-gnu-emacs@gnu.org; Thu, 26 Jan 2023 13:25:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pL6vm-0007dm-Fk for bug-gnu-emacs@gnu.org; Thu, 26 Jan 2023 13:25:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Jan 2023 18:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60953 X-GNU-PR-Package: emacs Original-Received: via spool by 60953-submit@debbugs.gnu.org id=B60953.167475748129335 (code B ref 60953); Thu, 26 Jan 2023 18:25:02 +0000 Original-Received: (at 60953) by debbugs.gnu.org; 26 Jan 2023 18:24:41 +0000 Original-Received: from localhost ([127.0.0.1]:36157 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pL6vN-0007d2-AN for submit@debbugs.gnu.org; Thu, 26 Jan 2023 13:24:40 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:44046) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pL6vL-0007cp-TO for 60953@debbugs.gnu.org; Thu, 26 Jan 2023 13:24:36 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pL6v8-0001vF-HP; Thu, 26 Jan 2023 13:24:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Qmi3YOXcojTNp5jsRt/GIVG3BHQUuoEkta292bTOkF8=; b=NW1CoQgMdg0u VHFjT1nEIpqgVOCURhiI9aRwQv6DIfz/I94mdYn/yaoR9q7BrxwNNNcTfpfQqz4NmWvaukpWqxhbd seh1mEOL4FwaM2U/0aR5/X0SAu2Gae2e+Y8GPTlLiTCC4hB4GOJMVADXurt43PtzFpV4bWBmxyNwn bOro9v3XSU6iyGcgEk8aKoFKs3Lyo213dMejSAzzRs/zXrZ/5xHeUE+ZsmtNHyhgT1ACtKJknVFLb XnmOHFNsaooxAA/2hxzVbd8cfRz1ky4F4BHS0RArWeCyE5Mwk1Vz5c++Oxygznvx19HVbSSLTl4wm i6AmGjxa5uNBwL+EU79jyg==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pL6v7-0008VX-If; Thu, 26 Jan 2023 13:24:21 -0500 In-Reply-To: <6f318afc-ca71-8b7e-c822-52e6635b5718@yandex.ru> (message from Dmitry Gutov on Thu, 26 Jan 2023 19:15:51 +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:254224 Archived-At: > Date: Thu, 26 Jan 2023 19:15:51 +0200 > Cc: 60953@debbugs.gnu.org > From: Dmitry Gutov > > On 26/01/2023 10:10, Eli Zaretskii wrote: > > Perhaps Dmitry could present comparison of profiles from perf which > > would allow us to understand the reason(s)? > > I believe I did that in the second message in this thread: > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60953#8 > > To quote the specific profiles, it's > > 15.30% emacs libtree-sitter.so.0.0 [.] > ts_tree_cursor_current_status > 14.92% emacs emacs [.] process_mark_stack > 9.75% emacs libtree-sitter.so.0.0 [.] > ts_tree_cursor_goto_next_sibling > 8.90% emacs libtree-sitter.so.0.0 [.] > ts_tree_cursor_goto_first_child > 3.87% emacs libtree-sitter.so.0.0 [.] ts_node_start_point > > for :pred vs. > > 23.72% emacs emacs [.] process_mark_stack > 12.33% emacs libtree-sitter.so.0.0 [.] > ts_tree_cursor_current_status > 7.96% emacs libtree-sitter.so.0.0 [.] > ts_tree_cursor_goto_next_sibling > 7.38% emacs libtree-sitter.so.0.0 [.] > ts_tree_cursor_goto_first_child > 3.37% emacs libtree-sitter.so.0.0 [.] ts_node_start_point > > for :match. > > And to continue the quote: > > Here's a significant jump in GC time which is almost the same as the > difference in runtime. And all of it is spent marking? > > I suppose if the problem is allocation of a large string (many times > over), the GC could be spending a lot of time scanning through the > memory. Could this be avoided by passing some substitute handle to TS, > instead of the full string? E.g. some kind of reference to it in the > regexp cache. If you are saying that GC is responsible, then running the benchmark with gc-cons-threshold set to most-positive-fixnum should produce a more interesting profile and perhaps a more interesting comparison. (But I thought you concluded that GC alone cannot explain the difference in performance?) Otherwise, the profiles are too similar to support any conclusions, and the fact that process_mark_stack is in a prominent place doesn't help.