unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Scrolling xdisp.c.  Room for optimisation in syntax.c/CC Mode.
@ 2014-10-18 18:19 Alan Mackenzie
  2014-10-18 20:28 ` Alan Mackenzie
  0 siblings, 1 reply; 13+ messages in thread
From: Alan Mackenzie @ 2014-10-18 18:19 UTC (permalink / raw)
  To: emacs-devel

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).



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-10-20 16:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-18 18:19 Scrolling xdisp.c. Room for optimisation in syntax.c/CC Mode Alan Mackenzie
2014-10-18 20:28 ` Alan Mackenzie
2014-10-19 16:37   ` Ulrich Mueller
2014-10-19 17:49     ` Eli Zaretskii
2014-10-19 18:05       ` Ulrich Mueller
2014-10-20  1:41     ` Stefan Monnier
2014-10-20  7:24       ` Ulrich Mueller
2014-10-20 15:45         ` Stefan Monnier
2014-10-20 16:55           ` Ulrich Mueller
2014-10-20  7:29   ` martin rudalics
2014-10-20 11:47     ` Alan Mackenzie
2014-10-20 12:05       ` martin rudalics
2014-10-20 12:22         ` Óscar Fuentes

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).