From: Alan Mackenzie <acm@muc.de>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 25706@debbugs.gnu.org
Subject: bug#25706: 26.0.50; Slow C file fontification
Date: Thu, 3 Dec 2020 10:48:23 +0000 [thread overview]
Message-ID: <X8jCdwtyCY6F2Y6E@ACM> (raw)
In-Reply-To: <53CC4F6E-716E-4D4B-8903-F32CCB676163@acm.org>
Hello, Mattias.
On Wed, Dec 02, 2020 at 16:06:43 +0100, Mattias Engdegård wrote:
> 2 dec. 2020 kl. 11.15 skrev Alan Mackenzie <acm@muc.de>:
> > I spent yesterday evening investigating the "CC Mode state cache", i.e.
> > the thing that keeps track of braces and open parens/brackets. I found a
> > place where it was unnecessarily causing scanning from BOB, and fixed it
> > provisionally. On doing a (time-scroll) on the entire monster buffer, it
> > saved ~25% of the run time. There is definitely something else scanning
> > repeatedly from BOB - the screen scrolling was more sluggish near the end
> > of the buffer than half way through.
I've found it. There was a "harmless" c-backward-syntactic-ws invocation
in c-determine-limit. This macro moves back over syntactic whitespace,
which includes macros. So this was going back all the way to BOB, from
which we scanned forward again.
In the enclosed patch (which includes my previous amendment) I've removed
this.
There are many other places which invoke c-backward-syntactic-ws without
giving the limit argument, and these slow down CC Mode too, though not as
dramatically as the removed one. I have given limits arguments to two of
these in c-font-complex-decl-prepare, which reduce the (time-scroll) time
for the last 10% of the entire monster file from ~77s to ~44s.
I intend to instrument c-backward-sws to determine which of the other
invocations of c-backward-syntactic-ws are most time consuming. There
are around 90 such calls in CC Mode. :-(
It now takes me just under 6 minutes to (time-scroll) through the entire
buffer, compared with a previous hour. As already mentioned, it is still
slightly more sluggish near the end of the buffer than near the start.
> > Here's that provisional patch, if you'd like to try it:
So, here's another provisional patch:
diff -r 863d08a1858a cc-engine.el
--- a/cc-engine.el Thu Nov 26 11:27:52 2020 +0000
+++ b/cc-engine.el Thu Dec 03 10:43:45 2020 +0000
@@ -3672,9 +3672,7 @@
how-far 0))
((<= good-pos here)
(setq strategy 'forward
- start-point (if changed-macro-start
- cache-pos
- (max good-pos cache-pos))
+ start-point (max good-pos cache-pos)
how-far (- here start-point)))
((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some sort of weighting.
(setq strategy 'backward
@@ -5778,8 +5776,6 @@
;; Get a "safe place" approximately TRY-SIZE characters before START.
;; This defsubst doesn't preserve point.
(goto-char start)
- (c-backward-syntactic-ws)
- (setq start (point))
(let* ((pos (max (- start try-size) (point-min)))
(s (c-semi-pp-to-literal pos))
(cand (or (car (cddr s)) pos)))
diff -r 863d08a1858a cc-fonts.el
--- a/cc-fonts.el Thu Nov 26 11:27:52 2020 +0000
+++ b/cc-fonts.el Thu Dec 03 10:43:45 2020 +0000
@@ -948,7 +948,7 @@
;; closest token before the region.
(save-excursion
(let ((pos (point)))
- (c-backward-syntactic-ws)
+ (c-backward-syntactic-ws (max (- (point) 500) (point-min)))
(c-clear-char-properties
(if (and (not (bobp))
(memq (c-get-char-property (1- (point)) 'c-type)
@@ -970,7 +970,7 @@
;; The declared identifiers are font-locked correctly as types, if
;; that is what they are.
(let ((prop (save-excursion
- (c-backward-syntactic-ws)
+ (c-backward-syntactic-ws (max (- (point) 500) (point-min)))
(unless (bobp)
(c-get-char-property (1- (point)) 'c-type)))))
(when (memq prop '(c-decl-id-start c-decl-type-start))
[ .... ]
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2020-12-03 10:48 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-13 18:20 bug#25706: 26.0.50; Slow C file fontification Sujith
2020-11-30 11:26 ` Lars Ingebrigtsen
2020-11-30 11:37 ` Lars Ingebrigtsen
2020-11-30 12:46 ` Mattias Engdegård
2020-11-30 12:49 ` Lars Ingebrigtsen
2020-11-30 16:27 ` Eli Zaretskii
2020-11-30 16:38 ` Alan Mackenzie
2020-11-30 16:53 ` Mattias Engdegård
2020-11-30 17:04 ` Mattias Engdegård
2020-12-01 5:48 ` Ravine Var
2020-12-01 13:34 ` Mattias Engdegård
2020-12-01 9:29 ` Alan Mackenzie
2020-12-01 9:44 ` martin rudalics
2020-12-01 10:07 ` Alan Mackenzie
2020-12-01 9:21 ` Alan Mackenzie
2020-12-01 12:03 ` Mattias Engdegård
2020-12-01 12:57 ` Alan Mackenzie
2020-12-01 14:07 ` Mattias Engdegård
2020-12-01 15:27 ` Alan Mackenzie
2020-12-01 18:59 ` Mattias Engdegård
2020-12-02 10:15 ` Alan Mackenzie
[not found] ` <X8dpQeGaDD1w3kXX@ACM>
2020-12-02 15:06 ` Mattias Engdegård
2020-12-03 10:48 ` Alan Mackenzie [this message]
2020-12-03 14:03 ` Mattias Engdegård
2020-12-04 21:04 ` Alan Mackenzie
[not found] ` <X8qkcokfZGbaK5A2@ACM>
2020-12-05 15:20 ` Mattias Engdegård
2020-12-08 18:42 ` Alan Mackenzie
[not found] ` <X8/JG7eD7SfkEimH@ACM>
2020-12-08 19:32 ` Mattias Engdegård
2020-12-09 7:31 ` Ravine Var
2020-12-09 7:47 ` Ravine Var
2020-12-10 8:08 ` Alan Mackenzie
2020-12-09 18:46 ` Alan Mackenzie
[not found] ` <X9Ebn7hKnG/vpDcZ@ACM>
2020-12-09 20:04 ` Eli Zaretskii
2020-12-09 20:32 ` Alan Mackenzie
2020-12-10 17:02 ` Ravine Var
2020-12-10 20:02 ` Alan Mackenzie
2020-12-11 10:55 ` Ravine Var
2020-12-12 15:34 ` Alan Mackenzie
[not found] ` <X9TjCeydJaE2mpK8@ACM>
2020-12-14 7:20 ` Ravine Var
2020-12-14 11:44 ` Alan Mackenzie
2020-12-15 4:01 ` Ravine Var
2020-12-15 12:27 ` Alan Mackenzie
2020-12-09 17:00 ` Mattias Engdegård
2020-12-10 12:26 ` Alan Mackenzie
2020-11-30 18:30 ` Alan Mackenzie
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=X8jCdwtyCY6F2Y6E@ACM \
--to=acm@muc.de \
--cc=25706@debbugs.gnu.org \
--cc=larsi@gnus.org \
--cc=mattiase@acm.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 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).