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 16:02:59 +0300 Message-ID: <9d84725f-fd46-ab26-3b54-97cb4cf45e33@gutov.dev> References: <878r919qfh.fsf@localhost> <72c93fb0-bf3e-3dad-69c0-2147cfa40f57@gutov.dev> <875y42xyex.fsf@localhost> <87zg1ewfc2.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="27387"; 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: 66117@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 22 15:04:13 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 1qjfpL-0006qF-CF for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Sep 2023 15:04:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjfpA-0006yz-Ai; Fri, 22 Sep 2023 09:04:00 -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 1qjfp2-0006qx-P9 for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 09:03:53 -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 1qjfp1-0001ae-RJ for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 09:03:52 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjfpB-0005x9-Vn for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 09:04: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 13:04:01 +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.169538780322835 (code B ref 66117); Fri, 22 Sep 2023 13:04:01 +0000 Original-Received: (at 66117) by debbugs.gnu.org; 22 Sep 2023 13:03:23 +0000 Original-Received: from localhost ([127.0.0.1]:35631 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjfoY-0005wF-Ok for submit@debbugs.gnu.org; Fri, 22 Sep 2023 09:03:23 -0400 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]:40149) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjfoU-0005vz-CL for 66117@debbugs.gnu.org; Fri, 22 Sep 2023 09:03:21 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4C76B5C01CA; Fri, 22 Sep 2023 09:03:02 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 22 Sep 2023 09:03:02 -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=fm1; t= 1695387782; x=1695474182; bh=wlt03/SCBjKsW6fZXMHoLw/00ekPPHyESCU hR2mzyZY=; b=0I1epA3FTajiDJPcnjQpCyV+s5n4oJaeIAyGLqIbgmZbhSGsZkr e2fFaDoootmYgzXxGRwmVPqsiX5JHsuguJjkLeJqAzf7A8XT/MPKTKYr8GlwaHA1 6q83sZ16egx3AwbYfdgephicRMMmMRbCVZLu3/B4WbFWR/RWMy3Rz/E8MEQsREqi XFdyfajul6rv6m8MDPijGxD5PvvEQfGB8JHy/aryj9blsV9/Wz5NNygXPb2EWHZK OXN/44TpD/xq29bwf7PJlGwP/gFd3ctrGE+Jx2kHgxL912eWdhlmc7z135SOSr3u YNukZadL+Wl3FQLTIY1+bJeJqNJ2EKd0Uaw== 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=fm2; t= 1695387782; x=1695474182; bh=wlt03/SCBjKsW6fZXMHoLw/00ekPPHyESCU hR2mzyZY=; b=apScNBinuGrzVKvXsSFm0+HOCZ7kOvtjMgex6/XKsxjaY5Bp0eh yHB475LWpjyV55wsHacc2PWWexnu8JApy1aGcpCtypt+1lrBHNuE9IEE8F6r0jB4 81WXTQzvw92dVlEpOrrN2gs6csqtUKm1/OMh63vfels71wH7gat71mZXYx/QNljK qNfcLrd1O2h5gAEu8A6MYYLtGm4bEF2WXdcnYyJ30R7F5dKTznoyjosWvW25Znk8 4SiDcGaPEybknTu4ia/qSzaQbM0O2v3PtOoJkU/o6RGHqfnrB76T5ygsf4j348zh pbZaotwJRRtW7Fr+8v/ZX8i2aYQs3crbyZw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekkedggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfevfhfhjggtgfesth ejredttdefjeenucfhrhhomhepffhmihhtrhihucfiuhhtohhvuceoughmihhtrhihsehg uhhtohhvrdguvghvqeenucggtffrrghtthgvrhhnpeeigfetveehveevffehledtueekie eikeeufeegudfgfeeghfdulefgfeevledvveenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpegumhhithhrhiesghhuthhovhdruggvvh X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Sep 2023 09:03:00 -0400 (EDT) Content-Language: en-US In-Reply-To: <87zg1ewfc2.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:271090 Archived-At: On 22/09/2023 15:41, Ihor Radchenko wrote: > Dmitry Gutov writes: > >>> Moreover, `find-buffer-visiting' is called by `find-file-noselect', and >>> I simply cannot make use of cache there without modifying the code >>> upstream; or writing my own version of `find-file-noselect' - bad idea >>> maintenance-wise. >> >> ...if most of said calls are done through find-file-noselect, I suppose >> that solution is a no-go. > > Not a no-go, but not a complete solution either. > I asked the user who provided the profiler report I have attached to > replace `find-buffer-visiting' with `get-file-buffer' in the relevant Org > sources and it did lead to ~30% runtime reduction. > > However, upon recording the profiler report with that change, > `find-buffer-visiting' still took a significant fraction of CPU time. > So, I decided to reach out upstream. Because the rest of the calls are made from Org? I see this in the profile, though: 6247 20% - editorconfig--advice-find-file-noselect There seems to be a lot of timers in that profile, and this is in one of them (under "Automatic GC" which takes up 53% of the time). So one was to improve this in the meantime would be to bring it up with "editorconfig" authors. I would even question the wisdom of advising find-file-noselect. > Will it be acceptable to implement the cache using variable watchers? I think variable watchers are mostly for debugging? I was thinking of a straight approach where the base primitives that visit a file or kill a buffer update said cache. >>> I think that the best way that will benefit more than Org mode is >>> arranging internal cache that will link buffer-file-name, >>> buffer-file-truename, and buffer-file-number with buffers; and maintain >>> the correctness of the cache if buffer-file-name changes for any reason. >> >> I think that is doable. >> >> It probably won't regress the performance of any particular scenario >> either, but we should benchmark opening a bunch of files this way anyway >> (might actually get faster, due to find-buffer-visiting calls). > > The regression might happen when the number of buffers is small - > when hash tables become slower compared to simple list lookup. > But in such scenario, we will be talking about very small absolute > runtimes anyway, so it should probably not matter in practice. I suppose.