[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CVS version: message mode + flyspell terribly slow

From: Chong Yidong
Subject: Re: CVS version: message mode + flyspell terribly slow
Date: Wed, 26 Nov 2008 16:30:33 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Chong Yidong <address@hidden> 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  <address@hidden>
>       * 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)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]