From: Alan Mackenzie <acm@muc.de>
To: emacs-devel@gnu.org
Subject: Scrolling xdisp.c. Room for optimisation in syntax.c/CC Mode.
Date: Sat, 18 Oct 2014 18:19:38 +0000 [thread overview]
Message-ID: <20141018181937.GA5924@acm.acm> (raw)
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).
next reply other threads:[~2014-10-18 18:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-18 18:19 Alan Mackenzie [this message]
2014-10-18 20:28 ` Scrolling xdisp.c. Room for optimisation in syntax.c/CC Mode 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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141018181937.GA5924@acm.acm \
--to=acm@muc.de \
--cc=emacs-devel@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.