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.devel Subject: Re: Tree-sitter navigation time grows as sqrt(line-number) Date: Thu, 17 Aug 2023 16:19:37 +0300 Message-ID: <6db52945-5459-197c-405d-153ff395a824@gutov.dev> References: <3E82D409-6903-4679-9031-939CA35791FF@gmail.com> <32507689-3b2c-ccbf-dd14-e7bf0bed1ac7@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25997"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: emacs-devel@gnu.org To: JD Smith Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Aug 17 15:20:48 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qWcvf-0006Z5-NP for ged-emacs-devel@m.gmane-mx.org; Thu, 17 Aug 2023 15:20:48 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWcui-0007OS-4S; Thu, 17 Aug 2023 09:19:48 -0400 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 1qWcug-0007Nu-I5 for emacs-devel@gnu.org; Thu, 17 Aug 2023 09:19:46 -0400 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWcud-0001YY-36 for emacs-devel@gnu.org; Thu, 17 Aug 2023 09:19:46 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 890F65C013F; Thu, 17 Aug 2023 09:19:40 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 17 Aug 2023 09:19:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1692278380; x=1692364780; bh=srfrdlZXYdQaKA4hz5/Kk7smVHIo8mjoi+q MzyyfGhY=; b=qADeRyQqmtjLsgH3P9sVLZ6maDvUhLMnnGuGpkbiBnSNBqYggTe CHBzFFT0noKjr/KkGNY2M3rDyjPgH5rnOQVPA0kP9xb3CkoaZBFn6r4Oi+LEv1Y0 NMWp8qx1jxOkLlLiEQ1xDG0MzWHthUGetfkcHAc/BnNVK4/+dNPbRgodVvKlTbtJ hdoafY6qa+lFvyZiQbXK9rpNoQr2gJ0EaFhVsixHe5bBaEY/cfUEd8bl0bKpzdZC DSGRXORQiBRyhvkvPbKHTVGyWfLjnkCj4y7FXqmM454QsaUIlARwmpStM64ECPjV 8/M/eR3QCIpwGiRUdXiWdoS1fBeu/6wHklA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1692278380; x=1692364780; bh=srfrdlZXYdQaKA4hz5/Kk7smVHIo8mjoi+q MzyyfGhY=; b=hgrslpYdJ/g4TUwUP6OrvtMm4N9iNgtJtqCkp4DBo4y3BF/54ml rRDSQoknxcWQ4j1BUCCTb/LDNfNOY0ldQAWXSCTtPP6BR4hKEfK1EfpWfEcCqiEm C97rdHsAHCi4++yH4XZMYqhtF3pszuS2tlxZEWEJR1cx5DS4w3UQVlSQ7t/VJLyM 0OQjDryuGek6wu0fDMWedFPilfJtqkXyVPFvATioQIod5Nt6WnpWLRSOXDEVxpLi zwDiccOFrdr1fda/6/2foC/DGdHXQOk1EQaCwy5gjyoQZ7rSamQtdhMzd1ugWDx6 otCfrgclJI9qlD1yaKSppXRdxONN+o8YwHg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudduuddgieefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffhvfevfhgjtgfgsehtjeertddtfeejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepjeegiedvfefghfduteeuveejgfefleeltedvtdefveekheevffeuuefhheej fffhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepug hmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 17 Aug 2023 09:19:39 -0400 (EDT) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=66.111.4.25; envelope-from=dmitry@gutov.dev; helo=out1-smtp.messagingengine.com X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-4.01, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:308860 Archived-At: On 17/08/2023 15:34, Dmitry Gutov wrote: > On 17/08/2023 15:21, JD Smith wrote: >> I provided the test code and target file in the hopes that others >> could confirm the scaling behavior and then experiment with algorithm >> tweaks, if anything obvious presented itself. > > I experimented a little bit with benchmarking (treesit-node-parent) > calls, and the patch came from that. In case somebody else here wants to try it: diff --git a/src/treesit.c b/src/treesit.c index 1f694e47201..4b35e5ee2e5 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -52,6 +52,7 @@ Copyright (C) 2021-2023 Free Software Foundation, Inc. #undef ts_node_named_descendant_for_byte_range #undef ts_node_next_named_sibling #undef ts_node_next_sibling +#undef ts_node_parent #undef ts_node_prev_named_sibling #undef ts_node_prev_sibling #undef ts_node_start_byte @@ -1899,16 +1900,27 @@ DEFUN ("treesit-node-parent", TSNode treesit_node = XTS_NODE (node)->node; Lisp_Object parser = XTS_NODE (node)->parser; - TSTreeCursor cursor; - if (!treesit_cursor_helper (&cursor, treesit_node, parser)) - return return_value; - if (ts_tree_cursor_goto_parent (&cursor)) - { - TSNode parent = ts_tree_cursor_current_node (&cursor); - return_value = make_treesit_node (parser, parent); - } - ts_tree_cursor_delete (&cursor); + if (treesit_node_uptodate_p(node)) + { + TSNode parent = ts_node_parent (treesit_node); + return_value = make_treesit_node (parser, parent); + } + else + { + Lisp_Object parser = XTS_NODE (node)->parser; + TSTreeCursor cursor; + if (!treesit_cursor_helper (&cursor, treesit_node, parser)) + return return_value; + + if (ts_tree_cursor_goto_parent (&cursor)) + { + TSNode parent = ts_tree_cursor_current_node (&cursor); + return_value = make_treesit_node (parser, parent); + } + ts_tree_cursor_delete (&cursor); + } + return return_value; }