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, 10 Dec 2020 20:02:44 +0000 Message-ID: References: <53CC4F6E-716E-4D4B-8903-F32CCB676163@acm.org> <05F2A660-A403-4B81-AE77-416A739160A7@acm.org> <878sa7h1a2.fsf@gmail.com> <878sa5twmq.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2916"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Lars Ingebrigtsen , 25706@debbugs.gnu.org To: Ravine Var Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 10 21:03:55 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 1knSAN-0000eI-2R for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 10 Dec 2020 21:03:55 +0100 Original-Received: from localhost ([::1]:46498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1knSAL-000432-Qt for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 10 Dec 2020 15:03:53 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knS9W-00042m-34 for bug-gnu-emacs@gnu.org; Thu, 10 Dec 2020 15:03:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56037) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1knS9V-0005uu-QV; Thu, 10 Dec 2020 15:03:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1knS9V-0007xF-NY; Thu, 10 Dec 2020 15:03:01 -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, 10 Dec 2020 20:03:01 +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.160763057330562 (code B ref 25706); Thu, 10 Dec 2020 20:03:01 +0000 Original-Received: (at 25706) by debbugs.gnu.org; 10 Dec 2020 20:02:53 +0000 Original-Received: from localhost ([127.0.0.1]:39350 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1knS9N-0007wr-Ag for submit@debbugs.gnu.org; Thu, 10 Dec 2020 15:02:53 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:40582 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1knS9L-0007wa-JR for 25706@debbugs.gnu.org; Thu, 10 Dec 2020 15:02:52 -0500 Original-Received: (qmail 65568 invoked by uid 3782); 10 Dec 2020 20:02:44 -0000 Original-Received: from acm.muc.de (p4fe15c51.dip0.t-ipconnect.de [79.225.92.81]) by localhost.muc.de (tmda-ofmipd) with ESMTP; Thu, 10 Dec 2020 21:02:44 +0100 Original-Received: (qmail 8303 invoked by uid 1000); 10 Dec 2020 20:02:44 -0000 Content-Disposition: inline In-Reply-To: <878sa5twmq.fsf@gmail.com> 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:195696 Archived-At: Hello, Ravine. On Thu, Dec 10, 2020 at 22:32:17 +0530, Ravine Var wrote: > > Thank you indeed for taking the trouble to test the patch on the lesser > > machine. I do not have access to such a machine. I am assuming that > > before this patch, such a large file like osprey_reg....h would have > > been completely unworkable on the machine. It sounds as though it still > > is. However, have you noticed any improvement at all in performance? > There is a marginal improvement - recovery from scroll lockups are > slightly faster. But, in general, working with the osprey header > file is still very painful. OK, I still have some work to do, here. > > Could I ask you please to do one more thing, and that is to take a > > profile on this machine where it is giving trouble. From a freshly > > loaded buffer, move forward (if necessary) to a troublesome spot. N.B. > > C-u 1 M-> moves to 10% away from the end of the buffer, C-u 2 M-> 20%, > > and so on. Then start the profiler and do what is causing sluggish > > performance. Then have a look at the final profiler output, and expand > > it sensibly so that the troublesome function can be found. [ .... ] > I opened the osprey file and started scrolling down and the screen > locked up. Here is the profile report (with emacs -Q): > https://gist.github.com/ravine-var/0c293968a902cde76af77f2872dde1d7 Thanks. That was very helpful. I've still got to analyse it more deeply, but one thing that stood out (to me, at least), was c-forward-name taking up 13% of the run time in your profile. If we include the garbage collection this will have caused, it might be as high as 20% of the time, and that's right at the beginnning of your buffer. To fix this, can I ask you, please, to try adding the following patch to your already patched software, and let me know if it helps at all. If it does, that's great, if not, could I ask you to do another profile for me on the less powerful machine, say by opening the buffer, starting the profiler, then moving to the middle of the buffer with C-u 5 M->. This may take some time to profile. Thanks! > I am using emacs master (along with your patch) built with LTO enabled > and CFLAGS set to '-O2 -march=native'. That's the ideal testing setup. Here's that patch: diff -r 863d08a1858a cc-engine.el --- a/cc-engine.el Thu Nov 26 11:27:52 2020 +0000 +++ b/cc-engine.el Tue Dec 08 19:48:50 2020 +0000 @@ -8276,7 +8325,8 @@ ;; typically called from `c-forward-type' in this case, and ;; the caller only wants the top level type that it finds to ;; be promoted. - c-promote-possible-types) + c-promote-possible-types + (lim+ (c-determine-+ve-limit 500))) (while (and (looking-at c-identifier-key) @@ -8306,7 +8359,7 @@ ;; Handle a C++ operator or template identifier. (goto-char id-end) - (c-forward-syntactic-ws) + (c-forward-syntactic-ws lim+) (cond ((eq (char-before id-end) ?e) ;; Got "... ::template". (let ((subres (c-forward-name))) @@ -8336,13 +8389,13 @@ (looking-at "::") (progn (goto-char (match-end 0)) - (c-forward-syntactic-ws) + (c-forward-syntactic-ws lim+) (eq (char-after) ?*)) (progn (forward-char) t)))) (while (progn - (c-forward-syntactic-ws) + (c-forward-syntactic-ws lim+) (setq pos (point)) (looking-at c-opt-type-modifier-key)) (goto-char (match-end 1)))))) @@ -8352,7 +8405,7 @@ (setq c-last-identifier-range (cons (point) (match-end 0))) (goto-char (match-end 0)) - (c-forward-syntactic-ws) + (c-forward-syntactic-ws lim+) (setq pos (point) res 'operator))) @@ -8366,7 +8419,7 @@ (setq c-last-identifier-range (cons id-start id-end))) (goto-char id-end) - (c-forward-syntactic-ws) + (c-forward-syntactic-ws lim+) (setq pos (point) res t))) @@ -8382,7 +8435,7 @@ ;; cases with tricky syntactic whitespace that aren't ;; covered in `c-identifier-key'. (goto-char (match-end 0)) - (c-forward-syntactic-ws) + (c-forward-syntactic-ws lim+) t) ((and c-recognize-<>-arglists @@ -8391,7 +8444,7 @@ (when (let (c-last-identifier-range) (c-forward-<>-arglist nil)) - (c-forward-syntactic-ws) + (c-forward-syntactic-ws lim+) (unless (eq (char-after) ?\() (setq c-last-identifier-range nil) (c-add-type start (1+ pos))) @@ -8406,7 +8459,7 @@ (when (and c-record-type-identifiers id-start) (c-record-ref-id (cons id-start id-end))) (forward-char 2) - (c-forward-syntactic-ws) + (c-forward-syntactic-ws lim+) t) (when (and c-record-type-identifiers id-start -- Alan Mackenzie (Nuremberg, Germany).