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

From: Eli Zaretskii <[email-masked]>
Date: Wed, 13 Dec 2023 15:51:39 +0200

> From: Ihor Radchenko <[email-masked]>
> Cc: [email-masked], [email-masked], [email-masked]
> Date: Wed, 13 Dec 2023 13:43:23 +0000
> 
> The simplest solution would be what `ido-make-buffer-list-1' does:
> 
>     ;; Each call to ido-ignore-item-p LET-binds case-fold-search.
>     ;; That is slow if there's no buffer-local binding available,
>     ;; roughly O(number of buffers).  This hack avoids it.
>     (setq-local case-fold-search nil)
> 
> But it will only solve specific problem with `find-buffer-visiting' and
> we can always go for it if we cannot find anything better.

Which other popular functions need to loop through all the buffers in
Lisp?

> I thought that trying to solve a more general problem would benefit more
> code - let-binding case-fold-search is extremely common across packages.

IMO, the general way you are trying to solve this makes this a very
hard problem with potentially Emacs-wide implications.  So we might as
well look for easier alternatives.

We could, for example, document the above trick, for those who need
it.

Or we could have a separate variable, which would not be a defcustom
nor automatically buffer-local, and will have the same effect as
case-fold-search on low-level searching and matching functions.

Btw, are you aware that many case-insensitive operations in Emacs
depend also on the case table in effect, which can also be
buffer-local?  So case-insensitive operations in Lisp can be
unexpectedly affected by stuff like the current buffer.  One more
reason to use them as little as possible.