From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko 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 11:03:34 +0000 Message-ID: <875y42xyex.fsf@localhost> References: <878r919qfh.fsf@localhost> <72c93fb0-bf3e-3dad-69c0-2147cfa40f57@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37830"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66117@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 22 13:03:06 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 1qjdwA-0009ed-Ri for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Sep 2023 13:03:06 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjdvx-00038n-GR; Fri, 22 Sep 2023 07:02:53 -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 1qjdvv-00038e-Vd for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 07:02: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 1qjdvv-0007CK-K6 for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 07:02:51 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjdw5-00039e-Os for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 07:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 22 Sep 2023 11:03: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.169538056112097 (code B ref 66117); Fri, 22 Sep 2023 11:03:01 +0000 Original-Received: (at 66117) by debbugs.gnu.org; 22 Sep 2023 11:02:41 +0000 Original-Received: from localhost ([127.0.0.1]:35377 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjdvl-000393-Am for submit@debbugs.gnu.org; Fri, 22 Sep 2023 07:02:41 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:38233) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjdvg-00038l-NP for 66117@debbugs.gnu.org; Fri, 22 Sep 2023 07:02:40 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id D089C240029 for <66117@debbugs.gnu.org>; Fri, 22 Sep 2023 13:02:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1695380539; bh=WlgpjR94lCL9VVP8+KCWoxN4IEJZvbWPT/R8Z/116pY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=TkOsXDCRy1TmdogHJJuJxbk8T/EJ0XyPR+saiFR/PlvKocDRJeOzAntS1+S6JmZK1 pGxAur7xErAKDL2xDGl08CjMVwgDOf6hVsO7SmvVqvL4Qhw8JwcNACYPNRZZ8VWlNT m4zSLAE6arkkq3VyqqeeU3enEWisnXWlCPp/z2f2pQN55z0M4i/KRqH2YJY6ldi73P vAuXHawYtkfMiE/kE41k3wTw+jXLq7THNMe+wg4krB24Jf8uVkctH8Dfz0pY00ZJ8s fulcqWGFJ9QaRnoxb1bXDtWUqwF1mT0sT9Q3vTzDC7CD3A1eGRNCVwRLM2OwB6mjGd m9aUBQiMJE68g== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RsTqt6Wxqz6v2V; Fri, 22 Sep 2023 13:02:18 +0200 (CEST) In-Reply-To: <72c93fb0-bf3e-3dad-69c0-2147cfa40f57@gutov.dev> 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:271065 Archived-At: Dmitry Gutov writes: >> 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? Actually, mostly because I though that this discussion might be of interest for you. > 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). For me, the situation is different - a new not-yet-open file is looked up multiple times in a row, which is a bit more tricky. > 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. Sure. That's my plan to address older Emacs versions. But such iteration will involve copy-pasting a big part of `find-buffer-visiting' source code, which is not something I want to maintain in a long term (what if `find-buffer-visiting' changes in future?). 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. 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. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at