From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#10149: Emacs 24 hangs for several minutes with very large c++ files Date: Sat, 2 Nov 2019 10:09:31 +0000 Message-ID: <20191102100931.GA5738@ACM> References: <878sozw5nf.fsf@marxist.se> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="167706"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: 10149@debbugs.gnu.org, suvayu ali To: Stefan Kangas , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Nov 02 11:10:21 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iQqMN-000hQX-O7 for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Nov 2019 11:10:19 +0100 Original-Received: from localhost ([::1]:46158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQqML-0003qu-T7 for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Nov 2019 06:10:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40262) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQqM9-0003qg-S6 for bug-gnu-emacs@gnu.org; Sat, 02 Nov 2019 06:10:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iQqM8-00068j-ER for bug-gnu-emacs@gnu.org; Sat, 02 Nov 2019 06:10:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49380) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iQqM6-0005vs-ES; Sat, 02 Nov 2019 06:10:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iQqM6-000092-7N; Sat, 02 Nov 2019 06:10:02 -0400 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: Sat, 02 Nov 2019 10:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10149 X-GNU-PR-Package: emacs,cc-mode Original-Received: via spool by 10149-submit@debbugs.gnu.org id=B10149.1572689382522 (code B ref 10149); Sat, 02 Nov 2019 10:10:02 +0000 Original-Received: (at 10149) by debbugs.gnu.org; 2 Nov 2019 10:09:42 +0000 Original-Received: from localhost ([127.0.0.1]:58201 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iQqLk-00008K-Gc for submit@debbugs.gnu.org; Sat, 02 Nov 2019 06:09:42 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:21486 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1iQqLh-00008A-MH for 10149@debbugs.gnu.org; Sat, 02 Nov 2019 06:09:39 -0400 Original-Received: (qmail 95524 invoked by uid 3782); 2 Nov 2019 10:09:35 -0000 Original-Received: from acm.muc.de (p2E5D5AEB.dip0.t-ipconnect.de [46.93.90.235]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 02 Nov 2019 11:09:31 +0100 Original-Received: (qmail 6433 invoked by uid 1000); 2 Nov 2019 10:09:31 -0000 Content-Disposition: inline In-Reply-To: <878sozw5nf.fsf@marxist.se> 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-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:170782 Archived-At: Hello, Stefan and Eli. On Sat, Nov 02, 2019 at 00:14:44 +0100, Stefan Kangas wrote: > suvayu ali writes: > > Hi Emacs devs, > > I am seeing a weird problem. I have an automatically generated C++ class > > for some ntupled data for quick (but dirty) analysis. It has lots of > > (~1k) data members. Every time I try to navigate in that file and I > > reach the large block of text where the data members are declared[1], > > Emacs takes a long time to move the cursor (e.g. with commands like > > forward-paragraph or backward-paragraph) and the CPU usage on my > > Thinkpad X201 maxes out on one of the 4 logical cores. If I wait long > > enough (several minutes), Emacs 24 does manage to move the cursor to the > > end of the paragraph. However I don't see this problem with Emacs 23.3.1 > > (or vim). > > I can replicate this behaviour with `emacs -Q'. The file that causes the > > issue is attached with this email. I am using Emacs from the repo.or.cz > > git mirror. > > commit aecaa1ffa122258c0fbc580ccbfad268ea46b89d > > Author: Andreas Schwab > > Date: Sat Nov 26 10:10:36 2011 +0100 > > * grammars/bovine-grammar.el (bovine--grammar-newstyle-unquote): > > Avoid warning about old-style backquote. > > This is how I compile emacs: > > In GNU Emacs 24.0.91.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.7) > > of 2011-11-27 on mylaptop.example.com > > configured using `configure '--prefix=/opt/emacs-lisp' > > '--with-selinux' '--with-imagemagick'' > > Important settings: > > value of $LC_ALL: nil > > value of $LC_COLLATE: nil > > value of $LC_CTYPE: nil > > value of $LC_MESSAGES: nil > > value of $LC_MONETARY: nil > > value of $LC_NUMERIC: nil > > value of $LC_TIME: nil > > value of $LANG: en_IN.UTF-8 > > value of $XMODIFIERS: @im=ibus > > locale-coding-system: utf-8-unix > > default enable-multibyte-characters: t > > Since I don't actually get a backtrace, I am not sure what else I can > > provide. Please feel free to ask me if you need more information. > > Hope this helps. > > Footnotes: > > [1] The large chunk of commented text in the attached file > I do see a significant slowdown in navigating the file once I comment > out the block of code. It doesn't hang for several minutes for me, > but it takes 5-10 seconds for C-v, M-v depending on where point is. Yes. Scrolling speed has been a constant theme over the last few years, and several improvements have been made. However .... > Alan, any comments on this? Thanks for the profiler output, Eli. The problem is indeed in c-font-lock-single-decl, where the code is searching backwards for a possible opening paren of a `for' statement. It was using (in effect) backward-up-list without a limit for this. This steadily got slower as one moved further down the class, away from the class's opening {. The solution is to supply a limit to that search. I think the following patch should do the job. For me it speeds up a complete scroll from beginning to end of buffer by a factor of ~4: diff -r 2783baa48d44 cc-fonts.el --- a/cc-fonts.el Fri Oct 25 20:00:14 2019 +0000 +++ b/cc-fonts.el Sat Nov 02 10:01:47 2019 +0000 @@ -1245,7 +1245,7 @@ (if (save-excursion (and (car (cddr decl-or-cast)) ; maybe-expression flag. - (c-go-up-list-backward) + (c-go-up-list-backward nil (c-determine-limit 500)) (eq (char-after) ?\() (progn (c-backward-syntactic-ws) (c-simple-skip-symbol-backward)) I will commit this properly probably later today, assuming nothing further untoward is found. > Best regards, > Stefan Kangas -- Alan Mackenzie (Nuremberg, Germany).