From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: CVS version: message mode + flyspell terribly slow Date: Wed, 26 Nov 2008 16:30:33 -0500 Message-ID: <871vwy41l2.fsf@cyd.mit.edu> References: <87iqqa9pc4.fsf@cyd.mit.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1227735031 17871 80.91.229.12 (26 Nov 2008 21:30:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 26 Nov 2008 21:30:31 +0000 (UTC) Cc: kzeitler@alcatel-lucent.com, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 26 22:31:33 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L5Ryu-0003EM-Ku for ged-emacs-devel@m.gmane.org; Wed, 26 Nov 2008 22:31:32 +0100 Original-Received: from localhost ([127.0.0.1]:41171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5Rxk-00062Y-Nw for ged-emacs-devel@m.gmane.org; Wed, 26 Nov 2008 16:30:20 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L5Rxe-0005yY-Jp for emacs-devel@gnu.org; Wed, 26 Nov 2008 16:30:14 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L5Rxd-0005w9-EG for emacs-devel@gnu.org; Wed, 26 Nov 2008 16:30:13 -0500 Original-Received: from [199.232.76.173] (port=59373 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5Rxd-0005vl-8N for emacs-devel@gnu.org; Wed, 26 Nov 2008 16:30:13 -0500 Original-Received: from cyd.mit.edu ([18.115.2.24]:51128) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L5Rxd-0000n6-1Z for emacs-devel@gnu.org; Wed, 26 Nov 2008 16:30:13 -0500 Original-Received: by cyd.mit.edu (Postfix, from userid 1000) id 7EDDD57E1D1; Wed, 26 Nov 2008 16:30:33 -0500 (EST) In-Reply-To: <87iqqa9pc4.fsf@cyd.mit.edu> (Chong Yidong's message of "Wed, 26 Nov 2008 15:58:35 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:106210 Archived-At: Chong Yidong writes: >> 1. start CVS version: emacs -Q >> 2. C-x C-f >> 3. M-x message-mode >> 4. M-x flyspell-mode >> Now editing, even cursor movement (forward-char, backward-char), is >> unbearably slow. > > Here's the cause of the slowdown: > > 2008-05-07 Stefan Monnier > > * tool-bar.el: Choose images dynamically. To be precise, the change replaces the filter function for the [tool-bar] key, which used to be a simple lambda function that returns tool-bar-map. Now, it calls the function tool-bar-make-keymap, which maps over tool-bar-map performing some dynamic computation. It turns out that tool-bar-make-keymap is rather expensive, leading to slowdowns like the above when it is called repeatedly. I'm not sure why flyspell+message causes it to be called so often, though. Maybe a gnus hacker can enlighten us. If we want to make tool-bar-make-keymap less expensive, one way is to cache its computed value, in the same way that we cache tool-bar image specs. See attached patch, which seems to eliminate most of the slowdown. Stefan, WDYT? (I think it's correct to use frame-terminal as I do here, as part of the hash key. But someone may want to check if this causes problems reaping dead terminals.) *** trunk/lisp/tool-bar.el.~1.21.~ 2008-10-13 14:55:08.000000000 -0400 --- trunk/lisp/tool-bar.el 2008-11-26 16:20:14.000000000 -0500 *************** *** 92,101 **** --- 92,108 ---- (declare-function image-mask-p "image.c" (spec &optional frame)) + (defconst tool-bar-keymap-cache (make-hash-table :weakness t :test 'equal)) + (defun tool-bar-make-keymap (&optional ignore) "Generate an actual keymap from `tool-bar-map'. Its main job is to figure out which images to use based on the display's color capability and based on the available image libraries." + (let ((key (cons (frame-terminal) tool-bar-map))) + (or (gethash key tool-bar-find-image-cache) + (puthash key (tool-bar-make-keymap-1) tool-bar-find-image-cache)))) + + (defun tool-bar-make-keymap-1 (&optional ignore) (mapcar (lambda (bind) (let (image-exp plist) (when (and (eq (car-safe (cdr-safe bind)) 'menu-item)