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#66117: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers Date: Fri, 22 Sep 2023 04:36:50 +0300 Message-ID: <72c93fb0-bf3e-3dad-69c0-2147cfa40f57@gutov.dev> References: <878r919qfh.fsf@localhost> 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="40209"; 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 To: Ihor Radchenko , 66117@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 22 03:38:12 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 1qjV7S-000AFD-9Y for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Sep 2023 03:38:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjV7D-0005W5-1q; Thu, 21 Sep 2023 21:37:55 -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 1qjV7A-0005Vr-Mp for bug-gnu-emacs@gnu.org; Thu, 21 Sep 2023 21:37:52 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qjV7A-00022B-El for bug-gnu-emacs@gnu.org; Thu, 21 Sep 2023 21:37:52 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjV7K-00086s-E5 for bug-gnu-emacs@gnu.org; Thu, 21 Sep 2023 21:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 22 Sep 2023 01:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66117 X-GNU-PR-Package: emacs Original-Received: via spool by 66117-submit@debbugs.gnu.org id=B66117.169534663631111 (code B ref 66117); Fri, 22 Sep 2023 01:38:02 +0000 Original-Received: (at 66117) by debbugs.gnu.org; 22 Sep 2023 01:37:16 +0000 Original-Received: from localhost ([127.0.0.1]:35037 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjV6a-00085j-Dh for submit@debbugs.gnu.org; Thu, 21 Sep 2023 21:37:16 -0400 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:47767) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjV6S-000856-Cj for 66117@debbugs.gnu.org; Thu, 21 Sep 2023 21:37:12 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A1EF95C00D5; Thu, 21 Sep 2023 21:36:52 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 21 Sep 2023 21:36:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=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=fm1; t= 1695346612; x=1695433012; bh=+EVi6PHBJt/HuXF7aD1N9c5PFkqCqrE4YIU 3aFv1k6M=; b=CVckxRUkgupYbnBCA7KqyEmB4YBAsGUG/l1RuvXNuZkJhpKAMpl vP539uNeHJBQXm52+2WIkBX3mlbb8lZCMapBrNJlvvAWv7evCdLFPazSt7jkcoSV tx+2Eh4LOmJfbZhKHLRkMaGtG/TJ/ZxAi8d9ZqDW4CV5XztZNrlP8/oGek3Djyzg Tbqsrdzct9VVNF9t1tgVMKnW9kRySDbm7ioi2zLWXFJ5XNEAalKt7xvJ+3VkF5er 36juYrrRLOyG0FK+BdLGz8z7/V9aopsIRU2ymU/JQ+nve7PKzOSiPkhAi+s0zzWf 0+tXVd8y5xtSsFGMAdltfTsqfpakVeu3Cfg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm2; t=1695346612; x= 1695433012; bh=+EVi6PHBJt/HuXF7aD1N9c5PFkqCqrE4YIU3aFv1k6M=; b=C xw8OH+0UiQVf5kiyDwmqXkWkXFQPt0MbYC3HnDd8fRAYkFW8q2i6F5jV+nv+V7T1 xb99LjGYvQE1RjsjbOGYh5iIvWP+Cykw9zd3CsytoWNqaQ0V22K5s5t0G1sDiQtK 2GFHj3191lqfq9Q30kJ+VQ2ipxWDOE/YOo0nyoW7kzEmltD5pyuvLsVFuXJl/en4 2n+Wui3HvPuMVpcGCylRiuzJMpSMhL32UJPbwlGAt4CUwbLBRYkK5kii9uc6T6bd Mvm0y73szO3fIPgg9gHMlroB8Ty3KQJIiuorsodq+U1YaPfZto3YW8Cj+KyUA4kj R9aRosop/RfsyHwkwKCUA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtje ertddtfeejnecuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegumhhithhrhiesghhu thhovhdruggvvheqnecuggftrfgrthhtvghrnhepgeehtdehudejieetuedttdejkeehje etueekheffuddtjeeuvdefveeuveeiuddunecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhepughmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 21 Sep 2023 21:36:51 -0400 (EDT) Content-Language: en-US In-Reply-To: <878r919qfh.fsf@localhost> 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:271033 Archived-At: Hi Ihor, On 20/09/2023 11:53, Ihor Radchenko wrote: > In the attached profile, ~500 Org buffers are being opened and calls to > `find-buffer-visiting' take 12.4 sec out of total 30.9 sec - 1/3 of all > the execution time. After replacing some of the calls to > `find-buffer-visiting' with `get-file-buffer', the total execution time > decreased to ~20 sec, confirming that `find-buffer-visiting' is > contributing significantly to slow performance. > > Would it be possible to implement some kind of caching mechanism to be > used by `find-buffer-visiting'? I'm guessing you Cc'd me because of an existing comment inside xref.el? As you can see I decided not to use this function there, but even get-file-buffer wasn't as fast as I would've wanted, so there's a quick-and-dirty caching solution for sequential lookups (which assumes that the same file would be looked up multiple times in a row). Putting aside the perspective of maintaining a cache in the core (hopefully this will be discussed later in this feature request), any chance you could initialize that cache yourself first (by iterating through buffers and building file-truename -> buffer map), before you are doing those many lookups? Somewhere in org-agenda-list, perhaps. That should change the complexity from N*M to N+M, more or less.