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: Thu, 05 Oct 2023 11:27:55 +0000 Message-ID: <87zg0xia10.fsf@localhost> References: <878r919qfh.fsf@localhost> <72c93fb0-bf3e-3dad-69c0-2147cfa40f57@gutov.dev> <8734yqodqr.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20322"; 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 Thu Oct 05 13:27: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 1qoMVb-00051s-WC for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 05 Oct 2023 13:27:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoMVM-0003UE-2z; Thu, 05 Oct 2023 07:26:56 -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 1qoMVF-0003Tj-Ml for bug-gnu-emacs@gnu.org; Thu, 05 Oct 2023 07:26:49 -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 1qoMV9-0007vJ-W3 for bug-gnu-emacs@gnu.org; Thu, 05 Oct 2023 07:26:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qoMVR-0003Pa-SP for bug-gnu-emacs@gnu.org; Thu, 05 Oct 2023 07:27: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: Thu, 05 Oct 2023 11:27: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.169650521113096 (code B ref 66117); Thu, 05 Oct 2023 11:27:01 +0000 Original-Received: (at 66117) by debbugs.gnu.org; 5 Oct 2023 11:26:51 +0000 Original-Received: from localhost ([127.0.0.1]:46133 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qoMVH-0003P9-5k for submit@debbugs.gnu.org; Thu, 05 Oct 2023 07:26:51 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:42077) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qoMVB-0003Oq-I1 for 66117@debbugs.gnu.org; Thu, 05 Oct 2023 07:26:49 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 9C0E5240027 for <66117@debbugs.gnu.org>; Thu, 5 Oct 2023 13:26:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1696505180; bh=TT2ia8sSQc7F/plVnKKklWSfyPTL4TsJkrE74JLTKc4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=Id7nozL1onC3wuO/hiKrE7G7Iof7I+q6txltjjAG8wrxMAwaqf4QO6sM8VKolPcpU Bx2XHLahOZy1X+u1jDezxEhwRmpmCd2gzXIllS2P+k1k0kOp7ozpdS1Kra7Ns1os5x gQQX5bPmCz8JEPtDmYTGA/5TJQmgMyBVnjjwU5NyOQwlH7Dl2WodG8F/HaMtHaE8Lo o56fKPGPUk6TZ7dPkX3muubwKASXG0E8ivlvUAPBzZn6LlCnRHOwVMaMTTKwffHEgj rhCGraO56z6B0WapCA2unYx+D4MzJyH6qb+wToYX1E6Lvuw5UJMZnMBDhQ6mePXFak +Y/lwOOMZkroQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4S1Tlb6C9fz9rxF; Thu, 5 Oct 2023 13:26:19 +0200 (CEST) In-Reply-To: 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:271865 Archived-At: Dmitry Gutov writes: > I retested, and it seems most people here won't be impressed by my > example. Anyway: > > 1. Call (benchmark-run 1 (project-find-regexp "emacs") in an Emacs repo > checkout. > 2. Change xref--collect-matches to call get-file-buffer instead of > xref--find-file-buffer (which does some caching). 'M-x > byte-compile-file', (load "xref.elc"), and run the benchmark again. > > What I get here, is 3.60s vs 5.03. > > It's a 1.40s difference over ~95000 calls, though (this is how many > matches are produced). Which is meaningful for my case, but probably not > for yours. I can reproduce: ;; original code (benchmark-run 10 (project-find-regexp "emacs")) ; => (26.459992888000002 17 7.026558985999998) ;; changed `xref--find-file-buffer' to `get-file-buffer' (benchmark-run 10 (project-find-regexp "emacs")) ; => (43.623003254000004 18 8.161839762000001) Looking into `xref--find-file-buffer', all it does is memoizing the previous call. I think that we can easily achieve the same performance improvement by maintaining approximate cache for Fget_file_buffer - something like (if (and (gethash file cache) (equal (buffer-local-value 'buffer-file-name (gethash ...)) file)) ) Or maybe even cache the last call separately to not pay `gethash' call price. 100% reliable cache is not necessary in this scenario. And not necessary in my scenario, as I have found via my benchmarks in another message. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at