Subject: bug#66117: closed (Re: bug#66117: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 30 Dec 2023 13:25:02 +0000

Your bug report

#66117: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
66117: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66117
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#66117: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers
From: Eli Zaretskii <[email-masked]>
To: Ihor Radchenko <[email-masked]>
Cc: [email-masked], [email-masked], [email-masked]
Date: Sat, 30 Dec 2023 15:24:04 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Ihor Radchenko <[email-masked]>
> Cc: [email-masked], [email-masked], [email-masked]
> Date: Sat, 30 Dec 2023 12:51:09 +0000
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > Should we now close this bug?
> 
> Yes, I think. I hope that closing the bug will not make question to
> Stefan (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66117#373) fall
> through the cracks.

Thanks, closing.

Subject: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers
From: Ihor Radchenko <[email-masked]>
To: [email-masked]
Date: Wed, 20 Sep 2023 08:53:06 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

X-Debbugs-CC: Dmitry Gutov <[email-masked]>

Hello,

Background: Some Org users (especially org-roam users) often complain
that Org agenda is very slow (sometimes, tens of seconds or minutes)
when running it right after startup. The cause is often not Org agenda
itself, but Emacs opening files slowly.

In some cases, the main reason files are opened slowly is user-defined
hooks or various packages adding advices mindlessly. However, Emacs
itself is also taking a significant fraction of time when opening a
large number of buffers.

I have recently got data on opening a large number of Org files in
Emacs that clearly demonstrates that `file-buffer-visiting' (and thus
`find-file') scale poorly when the number of buffers increases. This is
especially clear when Org mode needs to open several hundreds of
not-yet-opened Org files in a new Emacs session.

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'?

In GNU Emacs 30.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.17.8) of 2023-09-19 built on localhost
Repository revision: 6721c616653279913f51f211b80614bff82c24c3
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: Gentoo Linux

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