Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 24A3A431FD0 for ; Tue, 8 Nov 2011 18:53:01 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BnZISlLgwMH9 for ; Tue, 8 Nov 2011 18:53:00 -0800 (PST) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id 4B18F431FB6 for ; Tue, 8 Nov 2011 18:53:00 -0800 (PST) X-AuditID: 1209190f-b7f6e6d0000008df-78-4eb9eb0bd86a Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id B6.37.02271.B0BE9BE4; Tue, 8 Nov 2011 21:52:59 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id pA92qwUC010993; Tue, 8 Nov 2011 21:52:59 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pA92qv2Y010455 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Tue, 8 Nov 2011 21:52:58 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RNyK3-0003aG-QX; Tue, 08 Nov 2011 21:55:31 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Use a single buffer invisibility spec to fix quadratic search cost. Date: Tue, 8 Nov 2011 21:55:28 -0500 Message-Id: <1320807328-13728-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.7.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFIsWRmVeSWpSXmKPExsUixG6nrsv9eqefwa9VehbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxofG+4wFW6QqmvqusDUw3hHtYuTkkBAwkTg/7Q0ThC0mceHe erYuRi4OIYF9jBKfn11ihnDWM0r8aWtkhHBOMEk8PbIPKrOZUWLywg3MIP1sAhoS2/YvZwSx RQSkJXbenc3axcjBwSygJvGnSwUkLCwQLXGpaREbiM0ioCqx+fZ6FhCbV8BB4sWMnywg5RIC ChLLdlRPYORdwMiwilE2JbdKNzcxM6c4NVm3ODkxLy+1SNdELzezRC81pXQTIygIOCX5dzB+ O6h0iFGAg1GJh/dy0U4/IdbEsuLK3EOMkhxMSqK8gq+AQnxJ+SmVGYnFGfFFpTmpxYcYJTiY lUR49+cA5XhTEiurUovyYVLSHCxK4ryNOxz8hATSE0tSs1NTC1KLYLIyHBxKErxTQYYKFqWm p1akZeaUIKSZODhBhvMADZ8AUsNbXJCYW5yZDpE/xagoJc5b9xQoIQCSyCjNg+uFRekrRnGg V4Qh2nmAEQ7X/QpoMBPQ4HbdbSCDSxIRUlINjGJJ+p9ftj9cJ/J8w3KHK4d4F8+XFjtza8+s ffXK5598CdPMlkpPu5j/Y8un1FXeqU9WeDTcWzLx08v7cwpePFQQLYtYLvz8vN6qp9duzd/U IOVp+3Al34Qwiz1R1baOIut+Lma32uOybNJOEZfim8zvauUC/SO0i2+2T2utOpe9Rt7wfsj8 zgtKLMUZiYZazEXFiQDveZVArQIAAA== X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2011 02:53:01 -0000 Buffer redisplay requires traversing the buffer's invisibility spec for every part of the display that has an 'invisible text or overlay property. Previously, the search buffer's invisibility spec list contained roughly one entry for each search result. As a result, redisplay took O(NM) time where N is the number of visible lines and M is the total number of results. On a slow computer, this is enough to make even buffer motion noticeably slow. Worse, during a search operation, redisplay is triggered for each search result (even if there are no visible buffer changes), so search was quadratic (O(NM^2)) in the number of search results. This change switches to using a single element buffer invisibility spec. To un-hide authors, instead of removing an entry from the invisibility spec, it simply removes the invisibility overlay from those authors. I tested using a query with 6633 results on a 9 year old machine. Before this patch, Emacs took 70 seconds to fill the search buffer; toward the end of the search, Emacs consumed 10-20x as much CPU as notmuch; and moving point in the buffer took about a second. With this patch, the same query takes 40 seconds, Emacs consumes ~3x the CPU of notmuch by the end, and there's no noticeable lag to moving point. (There's still some source of non-linearity, because Emacs and notmuch consume roughly the same amount of CPU early in the search.) --- emacs/notmuch.el | 11 +++-------- 1 files changed, 3 insertions(+), 8 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index bb7565c..58fdea0 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -378,7 +378,7 @@ Complete list of currently available key bindings: (make-local-variable 'notmuch-search-target-line) (set (make-local-variable 'notmuch-search-continuation) nil) (set (make-local-variable 'scroll-preserve-screen-position) t) - (add-to-invisibility-spec 'notmuch-search) + (add-to-invisibility-spec (cons 'ellipsis t)) (use-local-map notmuch-search-mode-map) (setq truncate-lines t) (setq major-mode 'notmuch-search-mode @@ -679,9 +679,6 @@ foreground and blue background." (append (overlay-get overlay 'face) attributes))))) notmuch-search-line-faces))) -(defun notmuch-search-isearch-authors-show (overlay) - (remove-from-invisibility-spec (cons (overlay-get overlay 'invisible) t))) - (defun notmuch-search-author-propertize (authors) "Split `authors' into matching and non-matching authors and propertize appropriately. If no boundary between authors and @@ -755,13 +752,11 @@ non-authors is found, assume that all of the authors match." (insert visible-string) (when (not (string= invisible-string "")) (let ((start (point)) - (invis-spec (make-symbol "notmuch-search-authors")) overlay) (insert invisible-string) - (add-to-invisibility-spec (cons invis-spec t)) (setq overlay (make-overlay start (point))) - (overlay-put overlay 'invisible invis-spec) - (overlay-put overlay 'isearch-open-invisible #'notmuch-search-isearch-authors-show))) + (overlay-put overlay 'invisible 'ellipsis) + (overlay-put overlay 'isearch-open-invisible #'delete-overlay))) (insert padding)))) (defun notmuch-search-insert-field (field date count authors subject tags) -- 1.7.7.1