From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Arnold Noronha Newsgroups: gmane.emacs.bugs Subject: bug#41029: Improve ido-switch-buffer performance when many buffers are open Date: Sat, 2 May 2020 10:05:21 -0700 Message-ID: <20200502170521.GA17319@tdrhq.com> References: <20200502154055.GA11238@tdrhq.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="BXVAT5kNtrzKuDFl" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="39596"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.10.1 (2018-07-13) To: 41029@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 02 19:08:15 2020 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 1jUvca-000ABd-QW for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 May 2020 19:08:12 +0200 Original-Received: from localhost ([::1]:55504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUvcZ-000072-T9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 May 2020 13:08:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jUvcR-00005G-E2 for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 13:08:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUvcQ-0005tx-Pg for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 13:08:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42272) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUvcQ-0005tR-C7 for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 13:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jUvcQ-0006i5-73 for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 13:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Arnold Noronha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 02 May 2020 17:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41029 X-GNU-PR-Package: emacs Original-Received: via spool by 41029-submit@debbugs.gnu.org id=B41029.158843923025723 (code B ref 41029); Sat, 02 May 2020 17:08:02 +0000 Original-Received: (at 41029) by debbugs.gnu.org; 2 May 2020 17:07:10 +0000 Original-Received: from localhost ([127.0.0.1]:53817 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jUvbZ-0006gk-Pd for submit@debbugs.gnu.org; Sat, 02 May 2020 13:07:10 -0400 Original-Received: from tdrhq.com ([23.24.196.129]:48322) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jUvZv-0006dl-Gm for 41029@debbugs.gnu.org; Sat, 02 May 2020 13:05:27 -0400 Original-Received: by tdrhq.com (Postfix, from userid 1000) id A43B2C20CB6; Sat, 2 May 2020 10:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tdrhq.com; s=201909; t=1588439121; bh=K160LmEGt1fDwSiI+sir0U7OW0u+j7OH89Gf3/3zAY0=; h=Date:From:To:Subject:References:In-Reply-To:From; b=mUrrXo1evZbRAqZRn+vbdU2yK8NWGX6Og17Rfo9ZQfA8wix6oum9s9egae0jAM2Xh oophgWG3kn/6xp7PaOrkw1utstRN1WpEJUq8YeX8kwJFwPzBV9K0aMhCSu6xo3hmtt ZBrqQi3TDLkt5SEgdnPxF4mSIjk67aryzLIy0VLB4MvQ2oIHXuunrfGLxLkrQFXjE5 2DZlTWJUjkPewaUomguV18Jmc0F7FYEFFQs00TT+1HIUJsye7k0qmg3JUzy80TNtPg yHHZN6zGwNJHROojemI3WgF6iHtaadhB2MzLklrldsCtch08ikAQbQsRQYlvBZUvlC KWav+P/7VXy5w== Content-Disposition: inline In-Reply-To: <20200502154055.GA11238@tdrhq.com> X-Mailman-Approved-At: Sat, 02 May 2020 13:07:08 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 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" Xref: news.gmane.io gmane.emacs.bugs:179527 Archived-At: --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, May 02, 2020 at 08:40:55AM -0700, Arnold Noronha wrote: > + (flet ((inner () 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.) --BXVAT5kNtrzKuDFl Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Avoid-binding-CASE-FOLD-SEARCH-in-tight-loop.patch" >From 3bb4ec9bb2ae503b059957e99234fb8155ca9857 Mon Sep 17 00:00:00 2001 From: Arnold Noronha 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 --BXVAT5kNtrzKuDFl--