From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Scrolling xdisp.c. Room for optimisation in syntax.c/CC Mode. Date: Sat, 18 Oct 2014 18:19:38 +0000 Message-ID: <20141018181937.GA5924@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1413656756 20218 80.91.229.3 (18 Oct 2014 18:25:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Oct 2014 18:25:56 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 18 20:25:49 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XfYhI-0008EU-TT for ged-emacs-devel@m.gmane.org; Sat, 18 Oct 2014 20:25:49 +0200 Original-Received: from localhost ([::1]:37429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfYhI-00057W-EJ for ged-emacs-devel@m.gmane.org; Sat, 18 Oct 2014 14:25:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfYgx-00055h-OG for emacs-devel@gnu.org; Sat, 18 Oct 2014 14:25:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfYgq-0003jX-7U for emacs-devel@gnu.org; Sat, 18 Oct 2014 14:25:27 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:56679 helo=mail.muc.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfYgp-0003jR-UP for emacs-devel@gnu.org; Sat, 18 Oct 2014 14:25:20 -0400 Original-Received: (qmail 72300 invoked by uid 3782); 18 Oct 2014 18:25:18 -0000 Original-Received: from acm.muc.de (pD95182DA.dip0.t-ipconnect.de [217.81.130.218]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 18 Oct 2014 20:25:17 +0200 Original-Received: (qmail 6075 invoked by uid 1000); 18 Oct 2014 18:19:38 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:175539 Archived-At: 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).