emacs-devel
[Top][All Lists]
Advanced

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

RE: Q on performance with 10000 faces


From: Drew Adams
Subject: RE: Q on performance with 10000 faces
Date: Thu, 25 May 2006 09:21:42 -0700

           OK. I pared it down a bit to send along, and then I tried it
           in emacs -q. Result: I do not see the huge slowdown in emacs
           -q. So, there must be somthing else that I'm doing in my own
           environment.

    When I do track this down a bit more, I suspect it will be a
    combination of things - I've already seen an improvement by getting
    rid of some stuff on pre/post-command-hook.

    If that's the case, and given that without the 10000-face
    palette I do get good response time, then I will perhaps post the
    palette code in hopes that someone can check it and see why it slows
    things down so much (i.e. see if the re-display can be optimized a
    bit more).

I finally found some time to play with elp a bit, after getting rid of
various hooks (pre/post-command, minibuffer-setup/exit). As I suspected, I
didn't notice anything special. I suspect the overall slowness is a
combination of less-noticeable slowdowns due to some of the hooks and the
palette code.

In hopes that someone might be able to see why the palette code slows things
down (or suggest improvements to it), here is the basic code:
_________________________________________________________

;; from library hexrgb.el
(eval-when-compile (require 'cl)) ;; case

(defun approx-equal (x y)
  "Return non-nil if numbers X and Y are approximately equal.
Taken from Elisp Info manual, node \"Comparison of Numbers\", with
\"fuzz-factor\" = 1.0e-8."
  (or (and (= x 0.0) (= y 0.0))
      (< (/ (abs (- x y))
            (max (abs x) (abs y)))
         1.0e-8)))

(defun hexrgb-hsv-to-hex (hue saturation value)
  "Return the hex RBG color string for inputs HUE, SATURATION, VALUE.
The inputs are each in the range 0 to 1."
  (hexrgb-color-values-to-hex
   (mapcar (lambda (x) (floor (* x 65535.0)))
           (hexrgb-hsv-to-rgb hue saturation value))))

(defun hexrgb-color-values-to-hex (values)
  "Convert list of rgb color VALUES to a hex string, #XXXXXXXXXXXX.
Each X in the string is a hexadecimal digit.
Input VALUES is as for the output of `x-color-values'."
  (concat "#"
          (hexrgb-int-to-hex (nth 0 values) 4) ; red
          (hexrgb-int-to-hex (nth 1 values) 4) ; green
          (hexrgb-int-to-hex (nth 2 values) 4))) ; blue

(defun hexrgb-int-to-hex (int &optional nb-digits)
  "Convert integer argument INT to a #XXXXXXXXXXXX format hex string.
Each X in the output string is a hexadecimal digit.
NB-DIGITS is the number of hex digits.  If INT is too large to be
represented with NB-DIGITS, then the result is truncated from the
left.  So, for example, INT=256 and NB-DIGITS=2 returns \"00\", since
the hex equivalent of 256 decimal is 100, which is more than 2 digits."
  (setq nb-digits (or nb-digits 4))
  (substring (format (concat "%0" (int-to-string nb-digits) "X") int)
             (- nb-digits)))

(defun hexrgb-hsv-to-rgb (hue saturation value)
  "Convert HUE, SATURATION, VALUE components to RGB (red, green, blue).
Each input component is 0.0 to 1.0, inclusive.
Returns a list of RGB components of value 0.0 to 1.0, inclusive."
  (let (red green blue int-hue fract pp qq tt ww)
    (if (approx-equal 0.0 saturation)
        (setq red value green value blue value) ; Gray
      (setq hue (* hue 6.0)             ; Sectors: 0 to 5
            int-hue (floor hue)
            fract (- hue int-hue)
            pp (* value (- 1 saturation))
            qq (* value (- 1 (* saturation fract)))
            ww (* value (- 1 (* saturation (- 1 (- hue int-hue))))))
      (case int-hue
        (0 (setq red value green ww blue pp))
        (1 (setq red qq green value blue pp))
        (2 (setq red pp green value blue ww))
        (3 (setq red pp green qq blue value))
        (4 (setq red ww green pp blue value))
        (otherwise (setq red value green pp blue qq))))
    (list red green blue)))

;; from library doremi-color.el
(defun palette ()
  "Display a hue x saturation color palette."
  (interactive)
  (let ((pop-up-frames t))
    (with-output-to-temp-buffer "Palette"
      (let* ((cells (make-string 10000 ?\s- ))
             (hue 0.999999) (sat 1.0) (index 0)
             (color "#000000000000") (hhh 0) (sss 0))
        (while (< index 10000)
          (setq sss 0)
          (while (< sss 100)
            (setq hue 0.999999 hhh 0)
            (while (< hhh 100)
              (put-text-property
               index (1+ index) 'face
               (cons 'background-color
                     (setq color (hexrgb-hsv-to-hex hue sat 1.0)))
               cells)
              (setq hue (* (- hue 0.01) 0.999) hhh (1+ hhh)
                    index (1+ index)))
            (setq sat (* sat 0.97) sss (1+ sss))))
        (set-buffer "Palette")
        (setq hhh 0 index 0)
        (while (< hhh 100)
          (insert (substring cells index (+ index 100)) ?\n)
          (setq hhh (1+ hhh) index (+ index 100)))))
    (select-window (get-buffer-window "Palette" 'visible))
    (modify-frame-parameters
     (selected-frame)
     `((font . "-*-Courier-*-*-*-*-3-*-*-*-*-*-iso8859-1")
       (menu-bar-lines . 0) (tool-bar-lines . 0)
       (left-fringe . 0) (right-fringe . 0)
       (minibuffer) (vertical-scroll-bars)
       (background-color . "Black") (mouse-color . "Black")
       (height . 101) (width . 101)
       (cursor-type . box) (cursor-color . "Black")))))





reply via email to

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