From: Arnold Noronha <arnold@tdrhq.com>
To: 41029@debbugs.gnu.org
Subject: bug#41029: Acknowledgement (Improve ido-switch-buffer performance when many buffers are open)
Date: Sat, 2 May 2020 09:30:18 -0700 [thread overview]
Message-ID: <20200502163018.GA6146@tdrhq.com> (raw)
In-Reply-To: <handler.41029.B.158843545619280.ack@debbugs.gnu.org>
[-- Attachment #1: Type: text/plain, Size: 155 bytes --]
Updated patch (FLET was causing warnings/errors even though it seemed
to work. I don't know enough of elisp's bootstrapping process to know
why exactly.)
[-- Attachment #2: 0001-Avoid-binding-CASE-FOLD-SEARCH-in-tight-loop.patch --]
[-- Type: text/x-diff, Size: 4027 bytes --]
From 3bb4ec9bb2ae503b059957e99234fb8155ca9857 Mon Sep 17 00:00:00 2001
From: Arnold Noronha <arnold@tdrhq.com>
Date: Sat, 2 May 2020 08:30:47 -0700
Subject: [PATCH] Avoid binding CASE-FOLD-SEARCH in tight loop
IDO-IGNORE-ITEM-P is called for every buffer when switching
buffers. However, that function binds CASE-FOLD-SEARCH, which
appears to be an O(n) operation where n is (length (buffer-list)).
So we avoid binding it if we know we don't need to as a workaround.
To test this, this this:
(loop for i from 0 to 6000
do
(find-file (format "/tmp/xy%d.txt" i)))
Then try switching buffers with and without this patch.
---
lisp/ido.el | 67 ++++++++++++++++++++++++++++-------------------------
1 file changed, 36 insertions(+), 31 deletions(-)
diff --git a/lisp/ido.el b/lisp/ido.el
index 81883402ad..a2394d1d37 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -3408,7 +3408,7 @@ ido-make-merged-file-list
(defun ido-make-buffer-list-1 (&optional frame visible)
"Return list of non-ignored buffer names."
(delq nil
- (mapcar
+ (mapcar
(lambda (x)
(let ((name (buffer-name x)))
(if (not (or (ido-ignore-item-p name ido-ignore-buffers) (member name visible)))
@@ -3823,36 +3823,41 @@ ido-ignore-item-p
(and
ido-process-ignore-lists re-list
(save-match-data
- (let ((ext-list (and ignore-ext ido-ignore-extensions
- completion-ignored-extensions))
- (case-fold-search ido-case-fold)
- ignorep nextstr
- (flen (length name)) slen)
- (while ext-list
- (setq nextstr (car ext-list))
- (if (cond
- ((stringp nextstr)
- (and (>= flen (setq slen (length nextstr)))
- (string-equal (substring name (- flen slen)) nextstr)))
- ((functionp nextstr) (funcall nextstr name))
- (t nil))
- (setq ignorep t
- ext-list nil
- re-list nil)
- (setq ext-list (cdr ext-list))))
- (while re-list
- (setq nextstr (car re-list))
- (if (cond
- ((stringp nextstr) (string-match nextstr name))
- ((functionp nextstr) (funcall nextstr name))
- (t nil))
- (setq ignorep t
- re-list nil)
- (setq re-list (cdr re-list))))
- ;; return the result
- (if ignorep
- (setq ido-ignored-list (cons name ido-ignored-list)))
- ignorep)))))
+ (let ((inner (lambda ()
+ (let ((ext-list (and ignore-ext ido-ignore-extensions
+ completion-ignored-extensions))
+ ignorep nextstr
+ (flen (length name)) slen)
+ (while ext-list
+ (setq nextstr (car ext-list))
+ (if (cond
+ ((stringp nextstr)
+ (and (>= flen (setq slen (length nextstr)))
+ (string-equal (substring name (- flen slen)) nextstr)))
+ ((functionp nextstr) (funcall nextstr name))
+ (t nil))
+ (setq ignorep t
+ ext-list nil
+ re-list nil)
+ (setq ext-list (cdr ext-list))))
+ (while re-list
+ (setq nextstr (car re-list))
+ (if (cond
+ ((stringp nextstr) (string-match nextstr name))
+ ((functionp nextstr) (funcall nextstr name))
+ (t nil))
+ (setq ignorep t
+ re-list nil)
+ (setq re-list (cdr re-list))))
+ ;; return the result
+ (if ignorep
+ (setq ido-ignored-list (cons name ido-ignored-list)))
+ ignorep))))
+
+ (if (eq case-fold-search ido-case-fold)
+ (funcall inner)
+ (let ((case-fold-search ido-case-fold))
+ (funcall inner))))))))
;; Private variable used by `ido-word-matching-substring'.
(defvar ido-change-word-sub)
--
2.20.1
next prev parent reply other threads:[~2020-05-02 16:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-02 15:40 bug#41029: Improve ido-switch-buffer performance when many buffers are open Arnold Noronha
[not found] ` <handler.41029.B.158843545619280.ack@debbugs.gnu.org>
2020-05-02 16:30 ` Arnold Noronha [this message]
2020-05-02 17:05 ` Arnold Noronha
2020-05-02 18:26 ` Arnold Noronha
2020-05-03 2:03 ` Dmitry Gutov
2020-05-28 23:36 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200502163018.GA6146@tdrhq.com \
--to=arnold@tdrhq.com \
--cc=41029@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).