GNU bug report logs - #66117
30.0.50; `find-buffer-visiting' is slow when opening large number of buffers

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> posteo.net>

Date: Wed, 20 Sep 2023 08:53:02 UTC

Severity: minor

Found in version 30.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: 66117 <at> debbugs.gnu.org
Subject: bug#66117: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers
Date: Fri, 22 Sep 2023 15:41:01 +0300
Dmitry Gutov <dmitry <at> gutov.dev> 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.

Will it be acceptable to implement the cache using variable watchers?

>> 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.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




This bug report was last modified 1 year and 135 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.