Subject: bug#33670: 26.1; very large c++-mode yank performance regression 25.3_1-x86_64 -> 26.1-x86_64

From: Eli Zaretskii <[email-masked]>
Date: Sat, 08 Dec 2018 09:49:20 +0200

> From: Chris Hecker <[email-masked]>
> Date: Fri, 7 Dec 2018 18:42:23 -0800
> 
> If I start emacs and visit a moderately large cpp file (18k LOC), and go
> to the same place in the middle of the file in both versions of emacs,
> then kill and yank the current line, the performance on 26.1 is easily
> 10x worse...the yank is instant in 25.3_1 and takes literally almost a
> second on 26.1 sometimes.  I decided to test this with a profiler run,
> so I went to the same line in both, killed the line, and evaled this:
> 
> (progn (profiler-start 'cpu) (yank) (profiler-report) (profiler-stop))
> 
> Here are the results:
> 
> 25.3_1:
> 
> - ...                                               1 100%
>    Automatic GC                                     1 100%
> 
> 
> 26.1:
> - command-execute                                  14 100%
>  - call-interactively                              14 100%
>   - funcall-interactively                          14 100%
>    - eval-expression                               14 100%
>     - eval                                         14 100%
>      - progn                                       14 100%
>       - yank                                       14 100%
>        - insert-for-yank                           14 100%
>         - insert-for-yank-1                        14 100%
>          - c-after-change                          13  92%
>           - mapc                                   13  92%
>            - #<compiled 0x9dcce1>                  13  92%
>             - c-after-change-re-mark-raw-strings    6  42%
>              - c-in-literal                         3  21%

Please load cc-mode.el manually as a .el file, and then do this
experiment again and show the profile.  As you see from the above,
most of the time is taken by some function in the
c-before-font-lock-functions, but it's hard to tell which, because
it is shown as a byte code.  Emacs 26 puts 5 functions on
c-before-font-lock-functions, whereas Emacs 25 used only 2, and it's
IMO important to see which one(s) take the lion's share of time.

Also, do you see this kind of degradation in any C++ source file of
comparable size, or is that particular file you used for the profile
especially slow?

Finally, was the line you yanked a line of code or a part of a
comment (or some other syntactic element)?  Does that matter?

Thanks.