Subject: bug#11545: 24.0.96-mac-2.92; Strange speed problem scrolling in C++ code

From: John Wiegley <[email-masked]>
Date: Sat, 26 May 2012 02:46:15 -0500

>>>>> Alan Mackenzie <[email-masked]> writes:

> Could you possibly check this is the case in your file.c++ using elp.
> Here's a quick recipe in case you haven't used it before: [ M-x
> elp-instrument-package <ret> c- <ret>.  Scroll with C-v, either once or an
> arbitrary number of times.  M-x elp-results.]

Results attached below.

> The cost of this correct fontification is the "slight" sluggishness being
> seen here.  It is likely possible to optimise this function somewhat, though
> probably it's now too late for Emacs 24.1.

I'd rather forgo the correctness for the speed, since cc-mode has never been
100% correct, but it's always been correct enough.

John

Function Name                                  Call Count  Elapsed Time  Average Time
c-font-lock-fontify-region                     1529        31.313269999  0.0204795748
c-beginning-of-decl-1                          3657        11.680622999  0.0031940451
c-font-lock-declarations                       1529        11.070964000  0.0072406566
c-find-decl-spots                              1529        11.035531000  0.0072174826
c-context-set-fl-decl-start                    1529        10.549607     0.0068996775
c-set-fl-decl-start                            1529        10.542452999  0.0068949986
c-beginning-of-statement-1                     3910        9.8793279999  0.0025266823
c-backward-sws                                 123582      8.8908430000  7.194...e-05
c-crosses-statement-barrier-p                  15967       7.1756169999  0.0004494029
c-parse-state                                  14667       6.1785950000  0.0004212582
c-parse-state-1                                14667       5.6588790000  0.0003858238
c-font-lock-enclosing-decls                    1529        4.462361      0.0029184833
c-determine-limit                              5498        3.4111050000  0.0006204265
c-append-to-state-cache                        14467       2.5331440000  0.0001750980
c-remove-stale-state-cache                     14425       2.0322649999  0.0001408849
c-forward-decl-or-cast-1                       6632        1.9189249999  0.0002893433
c-beginning-of-macro                           164245      1.8161729999  1.105...e-05
c-forward-type                                 18312       1.5136799999  8.266...e-05
c-in-knr-argdecl                               3367        1.5124650000  0.0004492025
c-syntactic-skip-backward                      3882        1.3911049999  0.0003583475
c-font-lock-enum-tail                          1529        1.1747370000  0.0007683041
c-font-lock-complex-decl-prepare               1529        0.786506      0.0005143924
c-backward-token-2                             21271       0.7062790000  3.320...e-05
c-literal-limits                               25371       0.7047289999  2.777...e-05
c-at-macro-vsemi-p                             30271       0.7038709999  2.325...e-05
c-font-lock-declarators                        3723        0.6608859999  0.0001775143
c-forward-name                                 18056       0.5404579999  2.993...e-05
c-parse-state-get-strategy                     14667       0.4485610000  3.058...e-05
c-cheap-inside-bracelist-p                     5015        0.4087189999  8.149...e-05
c-forward-sws                                  60915       0.3506809999  5.756...e-06
c-syntactic-re-search-forward                  7741        0.2931619999  3.787...e-05
c-syntactic-content                            10849       0.2439560000  2.248...e-05
c-forward-token-2                              5974        0.2161999999  3.619...e-05
c-add-type                                     3181        0.1633079999  5.133...e-05
c-append-lower-brace-pair-to-state-cache       153         0.1180970000  0.0007718758
c-state-semi-safe-place                        7045        0.1104430000  1.567...e-05
c-remove-stale-state-cache-backwards           242         0.0868989999  0.0003590867
c-beginning-of-current-token                   8514        0.0621019999  7.294...e-06
c-looking-at-inexpr-block                      342         0.0573979999  0.0001678304
c-state-get-min-scan-pos                       14865       0.0395270000  2.659...e-06
c-get-fallback-scan-pos                        106         0.039258      0.0003703584
c-forward-label                                274         0.0353939999  0.0001291751
c-get-cache-scan-pos                           14667       0.0347800000  2.371...e-06
c-beginning-of-syntax                          250         0.0315929999  0.0001263719
c-font-lock-doc-comments                       3058        0.0247469999  8.092...e-06
c-safe-position                                4286        0.0241799999  5.641...e-06
c-state-literal-at                             267         0.0240109999  8.992...e-05
c-on-identifier                                694         0.0237040000  3.415...e-05
c-after-conditional                            79          0.0234840000  0.0002972658
c-syntactic-end-of-macro                       684         0.0193390000  2.827...e-05
c-forward-annotation                           6632        0.0187899999  2.833...e-06
c-skip-comments-and-strings                    7979        0.0155589999  1.949...e-06
c-punctuation-in                               636         0.0123149999  1.936...e-05
c-forward-keyword-clause                       831         0.0096369999  1.159...e-05
c-fontify-recorded-types-and-refs              6869        0.0094569999  1.376...e-06
c-state-safe-place                             267         0.0069390000  2.598...e-05
c-end-of-macro                                 2442        0.0062260000  2.549...e-06
c-font-lock-invalid-string                     1031        0.0052879999  5.129...e-06
c-end-of-current-token                         1207        0.0048019999  3.978...e-06
c-state-balance-parens-backwards               202         0.00426       2.108...e-05
c-most-enclosing-brace                         1789        0.0022139999  1.237...e-06
c-renarrow-state-cache                         10          0.0010699999  0.0001069999
c-state-mark-point-min-literal                 10          0.001004      0.0001003999
c-forward-single-comment                       37          0.0004699999  1.270...e-05
c-at-toplevel-p                                2           0.00028       0.00014
c-forward-to-cpp-define-body                   8           8.099...e-05  1.012...e-05
c-search-uplist-for-classkey                   2           1.2e-05       6e-06
c-leave-cc-mode-mode                           3           4.999...e-06  1.666...e-06