From: Chong Yidong <cyd@stupidchicken.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: kzeitler@alcatel-lucent.com, emacs-devel@gnu.org
Subject: Re: CVS version: message mode + flyspell terribly slow
Date: Wed, 26 Nov 2008 16:30:33 -0500 [thread overview]
Message-ID: <871vwy41l2.fsf@cyd.mit.edu> (raw)
In-Reply-To: <87iqqa9pc4.fsf@cyd.mit.edu> (Chong Yidong's message of "Wed, 26 Nov 2008 15:58:35 -0500")
Chong Yidong <cyd@stupidchicken.com> writes:
>> 1. start CVS version: emacs -Q
>> 2. C-x C-f <message_file>
>> 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 <monnier@iro.umontreal.ca>
>
> * 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)
next prev parent reply other threads:[~2008-11-26 21:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-24 12:44 CVS version: message mode + flyspell terribly slow Klaus Zeitler
2008-11-24 19:00 ` Leo
2008-11-24 20:28 ` Chong Yidong
2008-11-26 20:19 ` Chong Yidong
2008-11-26 20:26 ` Chong Yidong
2008-11-26 20:58 ` Chong Yidong
2008-11-26 21:30 ` Chong Yidong [this message]
2008-11-27 2:52 ` Stefan Monnier
2008-11-27 3:42 ` Chong Yidong
2008-11-27 16:25 ` Stefan Monnier
2008-11-27 14:06 ` Klaus Zeitler
2008-11-27 18:23 ` Reiner Steib
-- strict thread matches above, loose matches on Subject: below --
2008-11-28 16:03 Chong Yidong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871vwy41l2.fsf@cyd.mit.edu \
--to=cyd@stupidchicken.com \
--cc=emacs-devel@gnu.org \
--cc=kzeitler@alcatel-lucent.com \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).