unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Eli Zaretskii <eliz@gnu.org>, martin rudalics <rudalics@gmx.at>
Cc: 16526@debbugs.gnu.org
Subject: bug#16526: 24.3.50; scroll-conservatively & c-mode regression
Date: Wed, 29 Jan 2014 21:52:40 +0000	[thread overview]
Message-ID: <20140129215240.GC3092@acm.acm> (raw)
In-Reply-To: <20140126204310.GA3937@acm.acm>

Hello, Eli, hello, Martin.

On Sun, Jan 26, 2014 at 08:43:10PM +0000, Alan Mackenzie wrote:
> On Sun, Jan 26, 2014 at 07:20:27PM +0200, Eli Zaretskii wrote:

> > You are right, sorry.  (I wasn't wrong, either: recenter does call the
> > same find_defun_start around EOB, which is what I saw.  But those
> > calls are very few and aren't responsible for the slowdown.  I also
> > wasn't wrong about point being at EOB, see below.  But I described
> > what happens incorrectly.)

> > Here's what I see in the debugger:

> > After beginning-of-buffer jumps to point-min, redisplay kicks in.
> > Since scroll-conservatively is set to a large value, redisplay first
> > tries to see whether it can bring point into view by scrolling the
> > window as little as possible.  It calls try_scrolling, which at some
> > point (around line 15000) tries to see whether the new location of
> > point is close enough to the current window start.  It does so by
> > calling move_it_to, which simulates the display.  While doing so,
> > move_it_to hits a portion of text with font-lock properties, and calls
> > JIT Lock to fontify them.

> > And here's where things go awry: For some reason, the CC Mode
> > fontification code decides it needs to scan the buffer backwards,
> > starting from EOB.

> The @dfn{state cache}, a list of certain brace/paren/bracket positions
> around some position, is set for a position near EOB.  With the switch to
> a different position, CC Mode tweaks the state cache rather than
> calculating it anew starting at BOB.  When the new position is nearer
> BOB, the code searches backwards for the appropriate braces.  However, it
> shouldn't be scanning the entire buffer backwards.  There is clearly a
> bug here.

> > So it goes temporarily to EOB (this is why I saw point being there),
> > and scans all the way back, I think in this loop from
> > c-append-lower-brace-pair-to-state-cache, which is called with its
> > first argument FROM set to EOB:

> > 	  ;; In the next pair of nested loops, the inner one moves back past a
> > 	  ;; pair of (mis-)matching parens or brackets; the outer one moves
> > 	  ;; back over a sequence of unmatched close brace/paren/bracket each
> > 	  ;; time round.
> > 	  (while
> > 	      (progn
> > 		(c-safe
> > 		  (while
> > 		      (and (setq ce (scan-lists bra -1 -1)) ; back past )/]/}; might signal
> > 			   (setq bra (scan-lists ce -1 1)) ; back past (/[/{; might signal
> > 			   (or (> bra here) ;(> ce here)
> > 			       (and
> > 				(< ce here)
> > 				(or (not (eq (char-after bra) ?\{))
> > 				    (and (goto-char bra)
> > 					 (c-beginning-of-macro)
> > 					 (< (point) macro-start-or-from))))))))
> > 		(and ce (< ce bra)))
> > 	    (setq bra ce))	; If we just backed over an unbalanced closing
> > 					; brace, ignore it.

> The backward scan-lists calls will be causing continual forward searches
> from BOB in syntax.c, every time the backward scan hits a comment ender.

> > This loop takes a lot of time, of course, and is a waste of time,
> > since eventually try_scrolling comes to the correct conclusion that
> > scrolling is impossible, and instead recenters at BOB.

> > Why does CC Mode decide to go from EOB backwards, I don't know;
> > presumably, this is decided by c-parse-state-get-strategy as part of
> > c-parse-state-1.

> Yes.  There is a bug here.  I have a strong suspicion where.

> [ .... ]

> > I hope this information will allow Alan to find the culprit and solve
> > the problem.

> Yes indeed, thanks.  But I'm not going to be able to resolve it in a
> scale of hours.  It's going to be days.  Sorry!

OK, here is a rough patch (smooth version to follow if it's any good),
which attempts to solve the problem by not calling
c-append-lower-brace-pair-to-state-cache in the pertinent circumstances.
Please try it out and let me know if it solves the problem (I still can't
reproduce the massive slowdown myself).



diff -r d6064f65b0a1 cc-engine.el
--- a/cc-engine.el	Sun Jan 19 12:09:59 2014 +0000
+++ b/cc-engine.el	Wed Jan 29 21:17:50 2014 +0000
@@ -2556,6 +2556,8 @@
   ;; o - ('forward START-POINT) - scan forward from START-POINT,
   ;;	 which is not less than the highest position in `c-state-cache' below here.
   ;; o - ('backward nil) - scan backwards (from HERE).
+  ;; o - ('back-and-forward START-POINT) - like 'forward, but when HERE is earlier
+  ;;     than GOOD-POS.
   ;; o - ('IN-LIT nil) - point is inside the literal containing point-min.
   (let ((cache-pos (c-get-cache-scan-pos here))	; highest position below HERE in cache (or 1)
 	strategy	    ; 'forward, 'backward, or 'IN-LIT.
@@ -2570,9 +2572,10 @@
      ((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some sort of weighting.
       (setq strategy 'backward))
      (t
-      (setq strategy 'forward
+      (setq strategy 'back-and-forward
 	    start-point cache-pos)))
-    (list strategy (and (eq strategy 'forward) start-point))))
+    (list strategy ;(and (eq strategy 'forward)
+	  start-point)));)
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2857,7 +2860,7 @@
   ;; adjust it to get outside a string/comment.	 (Sorry about this!  The code
   ;; needs to be FAST).
   ;;
-  ;; Return a list (GOOD-POS SCAN-BACK-POS PPS-STATE), where
+  ;; Return a list (GOOD-POS SCAN-BACK-POS PPS-STATE), where  FIXME!!!
   ;; o - GOOD-POS is a position where the new value `c-state-cache' is known
   ;;   to be good (we aim for this to be as high as possible);
   ;; o - SCAN-BACK-POS, if not nil, indicates there may be a brace pair
@@ -2892,6 +2895,7 @@
 	     pos
 	     upper-lim	   ; ,beyond which `c-state-cache' entries are removed
 	     scan-back-pos
+	     cons-separated
 	     pair-beg pps-point-state target-depth)
 
 	;; Remove entries beyond HERE.  Also remove any entries inside
@@ -2913,7 +2917,8 @@
 		   (consp (car c-state-cache))
 		   (> (cdar c-state-cache) upper-lim))
 	  (setcar c-state-cache (caar c-state-cache))
-	  (setq scan-back-pos (car c-state-cache)))
+	  (setq scan-back-pos (car c-state-cache)
+		cons-separated t))
 
 	;; The next loop jumps forward out of a nested level of parens each
 	;; time round; the corresponding elements in `c-state-cache' are
@@ -2986,7 +2991,8 @@
 	  (setq c-state-cache (cons (cons pair-beg pos)
 				    c-state-cache)))
 
-	(list pos scan-back-pos pps-state)))))
+	;(when (< pos scan-back-pos) (setq scan-back-pos nil)) ; 2014-01-26  FIXME!!!
+	(list pos scan-back-pos pps-state cons-separated)))))
 
 (defun c-remove-stale-state-cache-backwards (here)
   ;; Strip stale elements of `c-state-cache' by moving backwards through the
@@ -3271,6 +3277,7 @@
 		     ; are no open parens/braces between it and HERE.
 	 bopl-state
 	 res
+	 cons-separated
 	 scan-backward-pos scan-forward-p) ; used for 'backward.
     ;; If POINT-MIN has changed, adjust the cache
     (unless (= (point-min) c-state-point-min)
@@ -3283,13 +3290,15 @@
 
     ;; SCAN!
     (cond
-     ((eq strategy 'forward)
+     ((memq strategy '(forward back-and-forward)) ;(eq strategy 'forward)
       (setq res (c-remove-stale-state-cache start-point here here-bopl))
       (setq cache-pos (car res)
 	    scan-backward-pos (cadr res)
-	    bopl-state (car (cddr res))) ; will be nil if (< here-bopl
+	    bopl-state (car (cddr res)) ; will be nil if (< here-bopl
 					; start-point)
-      (if scan-backward-pos
+	    cons-separated (car (cdddr res)))
+      (if (and scan-backward-pos
+	       (or cons-separated (eq strategy 'forward))) ;scan-backward-pos
 	  (c-append-lower-brace-pair-to-state-cache scan-backward-pos here))
       (setq good-pos
 	    (c-append-to-state-cache cache-pos here))


-- 
Alan Mackenzie (Nuremberg, Germany).





  parent reply	other threads:[~2014-01-29 21:52 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.12613.1390467262.10748.bug-gnu-emacs@gnu.org>
2014-01-23  8:53 ` bug#16526: 24.3.50; scroll-conservatively & c-mode regression martin rudalics
2014-01-24 15:45   ` martin rudalics
2014-01-24 20:48   ` Alan Mackenzie
     [not found]   ` <lbujij$1scv$1@colin.muc.de>
2014-01-25  3:50     ` Juanma Barranquero
2014-01-25  9:23     ` martin rudalics
     [not found]     ` <52E38286.1050306@gmx.at>
2014-01-25 10:30       ` Eli Zaretskii
2014-01-25 14:58         ` martin rudalics
     [not found]         ` <52E3D131.2090705@gmx.at>
2014-01-25 16:30           ` Eli Zaretskii
2014-01-25 16:48             ` martin rudalics
2014-01-25 17:29               ` Eli Zaretskii
2014-01-25 18:25                 ` martin rudalics
     [not found]                 ` <52E4019C.5080905@gmx.at>
2014-01-25 18:31                   ` Eli Zaretskii
2014-01-25 18:40                     ` Eli Zaretskii
2014-01-26 11:20                       ` martin rudalics
     [not found]                       ` <52E4EF61.3050404@gmx.at>
2014-01-26 17:20                         ` Eli Zaretskii
2014-01-26 20:43                           ` Alan Mackenzie
2014-01-27  8:21                             ` martin rudalics
2014-01-29 21:52                             ` Alan Mackenzie [this message]
2014-01-30 17:16                               ` Eli Zaretskii
2014-01-31 20:00                                 ` Alan Mackenzie
2014-01-31 20:16                                   ` Eli Zaretskii
     [not found]                             ` <52E61704.6050807@gmx.at>
2014-01-27 14:49                               ` Stefan Monnier
     [not found]                               ` <jwvvbx5fq2b.fsf-monnier+emacsbugs@gnu.org>
2014-01-27 17:25                                 ` martin rudalics
     [not found]                                 ` <52E69695.5040703@gmx.at>
2014-01-28  0:16                                   ` Stefan Monnier
2014-01-29 22:36                               ` Alan Mackenzie
     [not found]                               ` <20140129223626.GD3092@acm.acm>
2014-01-30  7:37                                 ` martin rudalics
2014-01-30 13:47                                   ` martin rudalics
     [not found]                                   ` <52EA57D6.5080403@gmx.at>
2014-01-30 17:15                                     ` Eli Zaretskii
2014-01-30 18:58                                       ` martin rudalics
     [not found]                                       ` <52EAA0C9.1090000@gmx.at>
2014-02-01 10:41                                         ` Eli Zaretskii
2014-02-02 13:18                                           ` martin rudalics
2014-02-02 17:40                                           ` Alan Mackenzie
     [not found]                                           ` <20140202174050.GA5365@acm.acm>
2014-02-02 18:07                                             ` Eli Zaretskii
2014-02-02 19:20                                               ` Alan Mackenzie
2014-02-02 20:53                                                 ` Eli Zaretskii
2014-02-05 23:00                                                   ` Alan Mackenzie
2014-02-06  6:01                                                     ` Eli Zaretskii
2014-06-22 16:49                                                       ` Eli Zaretskii
2014-06-22 19:32                                                         ` Alan Mackenzie
2014-06-22 20:04                                                           ` Eli Zaretskii
2014-06-25 21:32                                                         ` Alan Mackenzie
2014-06-26  2:51                                                           ` Stefan Monnier
2014-06-27 20:34                                                             ` Alan Mackenzie
2014-06-27 22:33                                                               ` Stefan Monnier
2014-06-27 22:54                                                                 ` Stefan Monnier
     [not found]                                                                 ` <jwv8uoim0bm.fsf-monnier+emacsbugs@gnu.org>
2014-06-28 13:00                                                                   ` Alan Mackenzie
2014-06-28 14:00                                                                     ` martin rudalics
2014-06-28 14:34                                                                     ` Stefan Monnier
     [not found]                                                                     ` <53AECA88.7010401@gmx.at>
2014-06-28 14:55                                                                       ` Alan Mackenzie
2014-06-28 15:12                                                                         ` Eli Zaretskii
2014-06-28 16:30                                                                           ` Alan Mackenzie
2014-06-29  8:44                                                                         ` martin rudalics
2014-06-29  9:17                                                                           ` Alan Mackenzie
2014-06-29 10:06                                                                             ` martin rudalics
     [not found]                                                                             ` <53AFE536.7010407@gmx.at>
2014-06-29 12:48                                                                               ` Alan Mackenzie
2014-06-29 14:18                                                                                 ` martin rudalics
2014-06-29 14:41                                                                                   ` Alan Mackenzie
     [not found]                                                                                   ` <20140629144151.GD2948@acm.acm>
2014-06-29 16:01                                                                                     ` martin rudalics
     [not found]                                                                                     ` <53B03876.9070307@gmx.at>
2014-06-29 17:49                                                                                       ` Alan Mackenzie
2014-06-30  7:55                                                                                         ` martin rudalics
2014-06-30 13:48                                                                                         ` Stefan Monnier
     [not found]                                                                                         ` <53B117D6.1050306@gmx.at>
2014-07-02 20:05                                                                                           ` Alan Mackenzie
     [not found]                                                                                           ` <20140702200522.GB3823@acm.acm>
2014-07-03  1:57                                                                                             ` Stefan Monnier
2014-07-03  8:40                                                                                             ` martin rudalics
     [not found]                                                                                             ` <jwv61jf2owy.fsf-monnier+emacsbugs@gnu.org>
2014-07-03 14:59                                                                                               ` Stefan Monnier
2014-07-04 18:27                                                                                                 ` Alan Mackenzie
2014-07-04 19:11                                                                                                   ` Stefan Monnier
2014-07-04 19:43                                                                                                   ` Stefan Monnier
2014-07-05  2:23                                                                                                     ` Stefan Monnier
2014-07-06 13:48                                                                                                       ` Alan Mackenzie
2014-07-07  1:52                                                                                                         ` Stefan Monnier
2014-07-07  7:07                                                                                                         ` martin rudalics
     [not found]                                                                                                         ` <jwvsimevsvz.fsf-monnier+emacsbugs@gnu.org>
2014-07-07  7:07                                                                                                           ` martin rudalics
2014-07-05 20:25                                                                                                     ` Alan Mackenzie
2014-07-05 23:06                                                                                                       ` Stefan Monnier
2014-07-04 19:29                                                                                               ` Alan Mackenzie
2014-07-05  1:52                                                                                                 ` Stefan Monnier
2014-07-05  7:47                                                                                                   ` Alan Mackenzie
2014-06-29 22:14                                                                                     ` Stefan Monnier
     [not found]                                                                                     ` <jwvionjjrn7.fsf-monnier+emacsbugs@gnu.org>
2014-07-02 18:40                                                                                       ` Alan Mackenzie
     [not found]                                                                                       ` <20140702184013.GA3823@acm.acm>
2014-07-02 19:40                                                                                         ` Stefan Monnier
     [not found]                                                                     ` <jwvsimpksv1.fsf-monnier+emacsbugs@gnu.org>
2014-06-28 17:33                                                                       ` Alan Mackenzie
     [not found]                                                                       ` <20140628173334.GB2632@acm.acm>
2014-06-29 21:39                                                                         ` Stefan Monnier
2014-01-27  8:20                           ` martin rudalics
2014-01-27 16:23                             ` Eli Zaretskii
2014-01-27 17:26                               ` martin rudalics
2014-01-26 11:19                     ` martin rudalics
2014-01-25 20:27           ` bug#16526: 24.3.50; scroll-conservatively & c-mode regression. The purpose of revision 116070 Alan Mackenzie
     [not found]           ` <20140125202721.GA3630@acm.acm>
2014-01-25 23:02             ` Stefan Monnier
2014-01-26  3:41             ` Eli Zaretskii
2014-01-26  9:54               ` Alan Mackenzie
2014-01-26 16:33                 ` Eli Zaretskii
2014-01-26 17:35             ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140129215240.GC3092@acm.acm \
    --to=acm@muc.de \
    --cc=16526@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=rudalics@gmx.at \
    /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 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).