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 08:40:55 -0700 Message-ID: <20200502154055.GA11238@tdrhq.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="C7zPtVaVf+AK4Oqc" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="35277"; 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 18:05:22 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 1jUudl-00092k-GN for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 May 2020 18:05:21 +0200 Original-Received: from localhost ([::1]:59932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUudk-0007Kb-G2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 May 2020 12:05:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jUudT-0006yh-3P for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 12:05:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUudS-0005RC-Fj for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 12:05:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42193) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUudS-0005QY-1w for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 12:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jUudR-000524-SG for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 12:05: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 16:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41029 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.158843545619280 (code B ref -1); Sat, 02 May 2020 16:05:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 May 2020 16:04:16 +0000 Original-Received: from localhost ([127.0.0.1]:53739 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jUuch-00050t-LI for submit@debbugs.gnu.org; Sat, 02 May 2020 12:04:16 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:59968) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jUuGG-0004L1-0n for submit@debbugs.gnu.org; Sat, 02 May 2020 11:41:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jUuGF-0006ws-EL for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 11:41:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUuGC-0006d7-Kw for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 11:41:03 -0400 Original-Received: from tdrhq.com ([23.24.196.129]:33126) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jUuGC-0006YT-1a for bug-gnu-emacs@gnu.org; Sat, 02 May 2020 11:41:00 -0400 Original-Received: by tdrhq.com (Postfix, from userid 1000) id 6FBD1C20CB6; Sat, 2 May 2020 08:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tdrhq.com; s=201909; t=1588434055; bh=zeTA8MFsjmGC/BLfHHbACsiGwlrJZnqK9r3fgrKtgUg=; h=Date:From:To:Subject:From; b=pECtenjuC/KvBvsmdeh+77aEhs4wLRWEeUWCboc5q5RLuRrXNS069FgcUdaYHDdjf RrtGhUyHFAFf6BzgdxStaGMp0lDoKhenmgzJzn3nH4uVxImNT2/DGnhgs77p9OVNcT JnaFJsSnWi9o6hYS1v980b6FxqcSomvgp8wwoHE2u/9JIJ+EUv0cLyGHMIBrAo++ko hnpnkqNYWyp4h1S8EDitgBGHWK+M9+IMdfaPHgVEPORP20SUeH5Q9aEYilwdWxEuaV KHR45PanuWUwIGCdGBe4+osdBBT4MWidO3RhpRujuu04e+F+ZLBSXF3WNEjarWCys8 xsqQ37R7Tiovw== Content-Disposition: inline Received-SPF: pass client-ip=23.24.196.129; envelope-from=arnold@tdrhq.com; helo=tdrhq.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/02 11:40:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Mailman-Approved-At: Sat, 02 May 2020 12:04:14 -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:179522 Archived-At: --C7zPtVaVf+AK4Oqc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Many of the buffer locals (in particular I think it's the SYMBOL_FORWARDED types --- my terminoly may be off), appear to be O(n) to bind, where n is the number of live buffers. I tried to see if I can optimize that binding process directly, but couldn't figure out a way to do it without changing current behavior, so I opted to just optimize ido-switch-buffer directly. After this patch, the performance is quite bearable at ~6000 buffers, but still not ideal. --C7zPtVaVf+AK4Oqc Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Avoid-binding-CASE-FOLD-SEARCH-in-tight-loop.patch" >From 3bc4eb78c365f4b4a387451f0b55264076a97c4b 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..d7a24ae1d7 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))))) + (flet ((inner () + (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) + (inner) + (let ((case-fold-search ido-case-fold)) + (inner)))))))) ;; Private variable used by `ido-word-matching-substring'. (defvar ido-change-word-sub) -- 2.20.1 --C7zPtVaVf+AK4Oqc--