From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail
From: Eli Zaretskii <eliz@gnu.org>
Newsgroups: gmane.emacs.bugs
Subject: bug#10149: Emacs 24 hangs for several minutes with very large c++
 files
Date: Sat, 02 Nov 2019 09:31:47 +0200
Message-ID: <83r22qka3g.fsf@gnu.org>
References: <CAMXnza1Zos3GrPyk0mDdsmFstomyUM12uSC-W5+Obs7MfAEHnw@mail.gmail.com>
 <878sozw5nf.fsf@marxist.se>
Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226";
	logging-data="82515"; mail-complaints-to="usenet@blaine.gmane.org"
Cc: acm@muc.de, 10149@debbugs.gnu.org, fatkasuvayu+linux@gmail.com
To: Stefan Kangas <stefan@marxist.se>
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Nov 02 08:32:13 2019
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>
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 <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>)
	id 1iQntM-000LJr-6y
	for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Nov 2019 08:32:12 +0100
Original-Received: from localhost ([::1]:45500 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>)
	id 1iQntL-0000os-3R
	for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Nov 2019 03:32:11 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44740)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1iQntD-0000oT-Pb
 for bug-gnu-emacs@gnu.org; Sat, 02 Nov 2019 03:32:05 -0400
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1iQntC-0003yp-7T
 for bug-gnu-emacs@gnu.org; Sat, 02 Nov 2019 03:32:03 -0400
Original-Received: from debbugs.gnu.org ([209.51.188.43]:49198)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1iQntC-0003yg-3F; Sat, 02 Nov 2019 03:32:02 -0400
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1iQntB-0000Om-UA; Sat, 02 Nov 2019 03:32:01 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Eli Zaretskii <eliz@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org
Resent-Date: Sat, 02 Nov 2019 07:32:01 +0000
Resent-Message-ID: <handler.10149.B10149.15726799111512@debbugs.gnu.org>
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.15726799111512
 (code B ref 10149); Sat, 02 Nov 2019 07:32:01 +0000
Original-Received: (at 10149) by debbugs.gnu.org; 2 Nov 2019 07:31:51 +0000
Original-Received: from localhost ([127.0.0.1]:58019 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1iQnt0-0000OJ-8U
 for submit@debbugs.gnu.org; Sat, 02 Nov 2019 03:31:51 -0400
Original-Received: from eggs.gnu.org ([209.51.188.92]:35659)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@gnu.org>) id 1iQnsy-0000O6-Iw
 for 10149@debbugs.gnu.org; Sat, 02 Nov 2019 03:31:49 -0400
Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:49491)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <eliz@gnu.org>)
 id 1iQnst-0003s9-0u; Sat, 02 Nov 2019 03:31:43 -0400
Original-Received: from [176.228.60.248] (port=1345 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@gnu.org>)
 id 1iQnss-0007S9-Dt; Sat, 02 Nov 2019 03:31:42 -0400
In-reply-to: <878sozw5nf.fsf@marxist.se> (message from Stefan Kangas on Sat,
 02 Nov 2019 00:14:44 +0100)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
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" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org
Original-Sender: "bug-gnu-emacs"
 <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>
Xref: news.gmane.org gmane.emacs.bugs:170760
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/170760>

> From: Stefan Kangas <stefan@marxist.se>
> Date: Sat, 02 Nov 2019 00:14:44 +0100
> Cc: Alan Mackenzie <acm@muc.de>, 10149@debbugs.gnu.org
> 
> > [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.
> 
> Alan, any comments on this?

The OP doesn't make it clear, and it took me some seconds to realize,
that to see the problem, one needs to _un_comment the commented chunk.

Here's the profile for paging through that part with C-v.  As is
clearly visible, the culprit is c-font-lock-single-decl.

- command-execute                                                9167  72%
 - call-interactively                                            9167  72%
  - funcall-interactively                                        9164  72%
   - scroll-up-command                                           9162  72%
    - scroll-up                                                  9125  71%
     - jit-lock-function                                         9124  71%
      - jit-lock-fontify-now                                     9124  71%
       - jit-lock--run-functions                                 9123  71%
        - run-hook-wrapped                                       9123  71%
         - #<compiled -0x1ffffffff85fe718>                       9123  71%
          - font-lock-fontify-region                             9123  71%
           - c-font-lock-fontify-region                          9123  71%
            - font-lock-default-fontify-region                   9014  71%
             - font-lock-fontify-keywords-region                 9003  70%
              - c-font-lock-declarations                         8645  68%
               - c-find-decl-spots                               8640  68%
                - #<compiled -0x1ffffffff9680598>                8579  67%
                 - c-font-lock-single-decl                       8453  66%
                  - c-font-lock-declarators                        39   0%
                   - c-do-declarators                              38   0%
                    - c-forward-declarator                         30   0%
                     - c-syntactic-re-search-forward                 14   0%
                        c-beginning-of-macro                        8   0%
                     - c-forward-name                               3   0%
                        c-forward-sws                               1   0%
                     - c-backward-sws                               1   0%
                        c-beginning-of-current-token                  1   0%
                      #<compiled -0x1ffffffff9680fb0>                  2   0%
                      c-forward-sws                                 1   0%
                    c-backward-sws                                  1   0%
                    c-fontify-recorded-types-and-refs                  1   0%
                 - c-forward-decl-or-cast-1                        98   0%
                  - c-forward-type                                 62   0%
                   - c-forward-name                                21   0%
                      c-forward-sws                                 7   0%
                   - c-check-qualified-type                        10   0%
                    - c-forward-over-compound-identifier                  8   0%
                     - c-forward-over-token                         6   0%
                        c-forward-sws                               3   0%
                       c-forward-sws                                1   0%
                       c-on-identifier                              1   0%
                   - c-add-type                                     4   0%
                    - c-syntactic-content                           4   0%
                       c-forward-sws                                2   0%
                     c-forward-keyword-clause                       2   0%
                     #<compiled -0x1ffffffff9736820>                  1   0%
                     #<compiled -0x1ffffffff8c38b48>                  1   0%
                     c-forward-sws                                  1   0%
                  - c-forward-name                                  6   0%
                     c-forward-sws                                  1   0%
                  - c-backward-token-2                              4   0%
                     c-backward-sws                                 3   0%
                     c-beginning-of-current-token                   1   0%
                  - c-backward-sws                                  3   0%
                     c-beginning-of-current-token                   2   0%
                    c-forward-sws                                   1   0%
                 - c-backward-sws                                  10   0%
                  - c-beginning-of-macro                            8   0%
                     back-to-indentation                            3   0%
                 - c-backward-token-2                               2   0%
                    c-backward-sws                                  2   0%
                - c-bs-at-toplevel-p                               42   0%
                 - c-brace-stack-at                                39   0%
                  - c-update-brace-stack                           39   0%
                     c-syntactic-re-search-forward                 38   0%
                  c-beginning-of-macro                              7   0%
                  c-forward-sws                                     4   0%
                c-font-lock-<>-arglists                            87   0%
              - c-font-lock-cut-off-declarators                    68   0%
               - c-back-over-member-initializers                   46   0%
                - c-parse-state                                    44   0%
                 - c-parse-state-1                                 44   0%
                  - c-append-to-state-cache                        28   0%
                   - c-beginning-of-macro                           1   0%
                      back-to-indentation                           1   0%
                  - c-remove-stale-state-cache                     16   0%
                   - c-beginning-of-macro                           1   0%
                      #<compiled -0x1ffffffff8c48290>                  1   0%
                  c-backward-sws                                    1   0%
               - c-determine-limit                                 20   0%
                - c-semi-pp-to-literal                             11   0%
                   c-restore-string-fences                          1   0%
               - c-syntactic-skip-backward                          1   0%
                - c-beginning-of-macro                              1   0%
                   back-to-indentation                              1   0%
              - c-font-lock-complex-decl-prepare                   61   0%
               - c-parse-state                                     59   0%
                - c-parse-state-1                                  59   0%
                   c-append-to-state-cache                         31   0%
                 - c-remove-stale-state-cache-backwards                 18   0%
                  - c-state-literal-at                              4   0%
                     c-state-pp-to-literal                          3   0%
                   - c-state-safe-place                             1   0%
                      c-state-pp-to-literal                         1   0%
                    c-state-balance-parens-backwards                  1   0%
                   c-remove-stale-state-cache                       9   0%
                 c-backward-sws                                     1   0%
               - c-beginning-of-macro                               1   0%
                  back-to-indentation                               1   0%
              - c-font-lock-enclosing-decls                        45   0%
               - c-parse-state                                     35   0%
                - c-parse-state-1                                  33   0%
                   c-append-to-state-cache                         22   0%
                   c-remove-stale-state-cache                      11   0%
                - c-beginning-of-macro                              1   0%
                   back-to-indentation                              1   0%
                 c-determine-limit                                  9   0%
               - c-syntactic-skip-backward                          1   0%
                  c-beginning-of-macro                              1   0%
              - c-font-lock-enum-tail                              35   0%
               - c-parse-state                                     23   0%
                - c-parse-state-1                                  22   0%
                   c-append-to-state-cache                         15   0%
                   c-remove-stale-state-cache                       6   0%
                - c-beginning-of-macro                              1   0%
                   back-to-indentation                              1   0%
               - c-backward-over-enum-header                       12   0%
                - c-backward-typed-enum-colon                       6   0%
                 - c-backward-token-2                               6   0%
                  - c-backward-sws                                  1   0%
                     c-beginning-of-current-token                   1   0%
                - c-backward-token-2                                4   0%
                 - c-backward-sws                                   3   0%
                  - c-beginning-of-macro                            2   0%
                     back-to-indentation                            2   0%
                    c-beginning-of-current-token                    1   0%
                  c-on-identifier                                   1   0%
              - #<compiled -0x1ffffffff8d285c8>                    31   0%
               - c-beginning-of-decl-1                             18   0%
                - c-beginning-of-statement-1                       16   0%
                 - c-crosses-statement-barrier-p                    7   0%
                    c-forward-sws                                   3   0%
                    c-literal-limits                                1   0%
                 - c-backward-sws                                   5   0%
                  - c-beginning-of-macro                            1   0%
                     back-to-indentation                            1   0%
                   c-beginning-of-macro                             1   0%
                - c-syntactic-re-search-forward                     1   0%
                   c-beginning-of-macro                             1   0%
               - c-determine-limit                                 11   0%
                - c-backward-sws                                    2   0%
                   c-beginning-of-macro                             1   0%
                - c-semi-pp-to-literal                              1   0%
                   c-semi-get-near-cache-entry                      1   0%
              - c-font-lock-raw-strings                             4   0%
               - c-semi-pp-to-literal                               4   0%
                  c-restore-string-fences                           1   0%
              - c-font-lock-invalid-single-quotes                   4   0%
               - c-literal-limits                                   2   0%
                  c-full-pp-to-literal                              2   0%
                #<compiled -0x1ffffffff8d28718>                     4   0%
                #<compiled -0x1ffffffff8d28948>                     3   0%
                #<compiled -0x1ffffffff8d28fb0>                     3   0%
                #<compiled -0x1ffffffff8d287b8>                     2   0%
                #<compiled -0x1ffffffff8d28ad8>                     2   0%
                c-font-lock-enum-body                               1   0%
                #<compiled -0x1ffffffffa13eaf0>                     1   0%
             - font-lock-fontify-syntactically-region                 11   0%
                syntax-ppss                                         7   0%
            - c-before-context-fl-expand-region                   108   0%
             - mapc                                               108   0%
              - #<compiled -0x1ffffffff8d25220>                   108   0%
               - c-context-expand-fl-region                       108   0%
                - c-fl-decl-end                                    79   0%
                 - c-slow-enclosing-c++-attribute                  74   0%
                  - c-parse-state                                  74   0%
                   - c-parse-state-1                               73   0%
                      c-append-to-state-cache                      50   0%
                    - c-remove-stale-state-cache                   17   0%
                     - c-beginning-of-macro                         2   0%
                        #<compiled -0x1ffffffff8c48290>                  1   0%
                    - c-parse-state-get-strategy                    5   0%
                     - c-get-fallback-scan-pos                      5   0%
                      - beginning-of-defun                          5   0%
                         beginning-of-defun-raw                     5   0%
                      c-beginning-of-macro                          1   0%
                   - c-beginning-of-macro                           1   0%
                      #<compiled -0x1ffffffff8c48290>                  1   0%
                 - c-literal-start                                  2   0%
                    c-semi-pp-to-literal                            2   0%
                   c-beginning-of-macro                             1   0%
                   c-on-identifier                                  1   0%
                   c-backward-sws                                   1   0%
                - c-fl-decl-start                                  29   0%
                 - c-determine-limit                               13   0%
                  - c-semi-pp-to-literal                            2   0%
                   - #<compiled -0x1ffffffff8c41948>                  1   0%
                      c-clear-string-fences                         1   0%
                    c-backward-sws                                  1   0%
                   c-literal-start                                  2   0%
                   c-syntactic-skip-backward                        1   0%
            - #<compiled -0x1ffffffff8d25120>                       1   0%
               c-clear-string-fences                                1   0%
     - eval                                                         1   0%
        if                                                          1   0%
   - execute-extended-command                                       2   0%
    - sit-for                                                       2   0%
     - redisplay                                                    1   0%
      - redisplay_internal (C function)                             1   0%
       - find-image                                                 1   0%
          image-search-load-path                                    1   0%
  - byte-code                                                       3   0%
   - read-extended-command                                          3   0%
    - completing-read                                               3   0%
     - completing-read-default                                      3   0%
        read-from-minibuffer                                        1   0%
+ redisplay_internal (C function)                                3078  24%
+ ...                                                             437   3%