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: Acknowledgement (Improve ido-switch-buffer performance when many buffers are open) Date: Sat, 2 May 2020 09:30:18 -0700 Message-ID: <20200502163018.GA6146@tdrhq.com> References: <20200502154055.GA11238@tdrhq.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="9jxsPFA5p3P2qPhR" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="40781"; 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:32 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 1jUvcs-000ATd-GT for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 May 2020 19:08:30 +0200 Original-Received: from localhost ([::1]:56710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUvcr-0000q8-If for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 May 2020 13:08:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jUvcR-00004s-3V 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-0005t8-D7 for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 13:08:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42271) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUvcP-0005sl-VL 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 1jUvcP-0006hy-Qy for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 13:08:01 -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:01 +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.158843922925717 (code B ref 41029); Sat, 02 May 2020 17:08:01 +0000 Original-Received: (at 41029) by debbugs.gnu.org; 2 May 2020 17:07:09 +0000 Original-Received: from localhost ([127.0.0.1]:53815 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jUvbZ-0006gi-Fe for submit@debbugs.gnu.org; Sat, 02 May 2020 13:07:09 -0400 Original-Received: from tdrhq.com ([23.24.196.129]:44192) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jUv20-0005g7-Eu for 41029@debbugs.gnu.org; Sat, 02 May 2020 12:30:25 -0400 Original-Received: by tdrhq.com (Postfix, from userid 1000) id 6ADB9C20CB6; Sat, 2 May 2020 09:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tdrhq.com; s=201909; t=1588437018; bh=4MiOqm9Vnv20nS/eDCT5h+VhSaAfnj6oOBYCmgaXalw=; h=Date:From:To:Subject:References:In-Reply-To:From; b=ExFbxxH1Wsx7M0MfOj8d1s6QJIvlf2fqiPjrQMn9CdIg3u7Umf/XcsFN7JS06mxbs rTyf2yzEy6lDxNibUR7zD+hWsWJcg5gY+duM9dJGhXXFUKC4GYKpF+YFRH7kQwieDq PZ9fH16H+rmPh5B7ecq28UZ3vGP2WnMewI/nTSonBEXKzpI8muaolthlTPvmIRH4W2 3CA0OoxEVH+FAJ7zC2ccAFJxzsqhqn/EwZgrwcM3NJwn4Wk/Dv4ZXlmIbsCUZkDNCj G+H6qipczno29mUyWMrdWwE1eiVWCE4AFuCdoYYxr3We5rnF8Q4IH2VkfIyrTj9sqB jXNC7QbBgWO3g== Content-Disposition: inline In-Reply-To: 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:179528 Archived-At: --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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.) --9jxsPFA5p3P2qPhR 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 --9jxsPFA5p3P2qPhR--