From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#25706: 26.0.50; Slow C file fontification Date: Thu, 3 Dec 2020 10:48:23 +0000 Message-ID: References: <27B320DF-8102-4CDF-8C6A-7157EEAACF64@acm.org> <956BCA08-0376-4FAD-B1F7-2087C03F6181@acm.org> <53CC4F6E-716E-4D4B-8903-F32CCB676163@acm.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31708"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , 25706@debbugs.gnu.org To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 03 11:49:30 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkmAz-00089a-GD for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Dec 2020 11:49:29 +0100 Original-Received: from localhost ([::1]:45926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkmAy-0001nK-Eu for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Dec 2020 05:49:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkmAa-0001WB-8i for bug-gnu-emacs@gnu.org; Thu, 03 Dec 2020 05:49:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55250) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kkmAY-0008QM-8j; Thu, 03 Dec 2020 05:49:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kkmAY-00038l-7Y; Thu, 03 Dec 2020 05:49:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Thu, 03 Dec 2020 10:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25706 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 25706-submit@debbugs.gnu.org id=B25706.160699251312036 (code B ref 25706); Thu, 03 Dec 2020 10:49:02 +0000 Original-Received: (at 25706) by debbugs.gnu.org; 3 Dec 2020 10:48:33 +0000 Original-Received: from localhost ([127.0.0.1]:38563 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kkmA5-000384-0m for submit@debbugs.gnu.org; Thu, 03 Dec 2020 05:48:33 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:46642 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1kkmA3-00037p-2p for 25706@debbugs.gnu.org; Thu, 03 Dec 2020 05:48:31 -0500 Original-Received: (qmail 83573 invoked by uid 3782); 3 Dec 2020 10:48:24 -0000 Original-Received: from acm.muc.de (p4fe159c7.dip0.t-ipconnect.de [79.225.89.199]) by localhost.muc.de (tmda-ofmipd) with ESMTP; Thu, 03 Dec 2020 11:48:23 +0100 Original-Received: (qmail 6538 invoked by uid 1000); 3 Dec 2020 10:48:23 -0000 Content-Disposition: inline In-Reply-To: <53CC4F6E-716E-4D4B-8903-F32CCB676163@acm.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:194872 Archived-At: 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 : > > 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).