emacs-devel
[Top][All Lists]
Advanced

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

Scrolling xdisp.c. Room for optimisation in syntax.c/CC Mode.


From: Alan Mackenzie
Subject: Scrolling xdisp.c. Room for optimisation in syntax.c/CC Mode.
Date: Sat, 18 Oct 2014 18:19:38 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

Hi, Emacs.

I've measured the time Emacs takes to scroll a large C file, and how much
of this is due to the inefficiency in backwards `scan-lists's when
comments contain unbalanced string characters (with
open-paren-in-column-0-is-defun-start nil).

Please load this file into your Emacs:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Track down block comments with an odd number of apostrophe's in them */
(defconst odd-apostrophes
  
"/\\*\\([^*']\\|\\*+[^*'/]\\)*\\(\\**'\\([^*']\\|\\*+[^*'/]\\)*\\**'\\([^*']\\|\\*+[^*'/]\\)*\\)*\\**\\('\\)\\([^*']\\|\\*+[^*'/]\\)*\\*+/"
  ;;     1                        2       3                             4       
                         5      6
)

(defun eradicate-odd-apostrophes ()
  (interactive)
  (let ((count 0))
    (while
        (re-search-forward odd-apostrophes nil t)
      (replace-match "`" nil t nil 5)
      (setq count (1+ count)))))

(defun time-backward-scrolls ()
  (interactive)
  (goto-char (point-max))
  (sit-for 1)
  (let (times this-time before (total 0.0))
    (while (condition-case nil
               (progn
                 (setq before (float-time))
                 (scroll-down-command)
                 (sit-for 0)
                 (setq this-time (- (float-time) before))
                 t)
             (error nil))
      (setq total (+ total this-time))
      (push this-time times)
      (sit-for 1))
    (message "%s scrolls, total time = %ss." (length times) total)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

First prepare a version of (Emacs 24) xdisp.c with all comments having
balanced string quotes.  Simply load xdisp.c into a buffer, place point
on L289 (just after the very large comment) and do M-x
eradicate-odd-apostrophes.  (The regexp `odd-apostrophes' matches a
block comment with an odd number of apostrophes, with submatch 5 matching
the last of these.)  Save this buffer under a new name, say
~/no-odd-xdisp.c.  (N.B. the regexp engine crashes out trying to match
the large comment.  In any case it's got 26 apostrophes, which is OK.)

Kill the buffer, then reload ~/no-odd-xdisp.c freshly.  Execute M-x
time-backward-scrolls.  This defun goes to EOB, then scrolls backwards to
BOB a page at a time.  It times the process.

Do the same with the original xdisp.c.

On my set up, a Linux virtual terminal with a window 65 lines high, I get
the following results:
    no-odd-xdisp.c: 492 scrolls, total time = 42.2749125957489s
           xdisp.c: 492 scrolls, total time = 69.40998315811157s.

69.4100 / 42.2749 = 1.642.  The original thus takes 64% longer (on
average) for a backward scroll operation.

It would seem worthwhile to consider optimising the code to eliminate
this 64%.  Two possibilities suggest themselves: (i) in syntax.c, by
making use of the syntax-ppss cache (or similar); (ii) In CC Mode, by
setting syntax-table text properties on unbalanced string quotes.

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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