Subject: bug#51006: 28.0.60; Slowness while navigating in inferior-python-mode

From: Simen Heggestøyl <[email-masked]>
Date: Mon, 04 Oct 2021 21:21:56 +0200

Eli Zaretskii <[email-masked]> writes:

> Please repeat the profiling experiment, but after loading python.el
> (NOT python.elc).  This should produce a more detailed profile that
> would pinpoint the culprit more accurately.  Based on skimming the
> source code, my first suspect is syntax-ppss, but that could be a bad
> guess.

Hi Eli, thanks for the quick response.

I repeated the experiment after deleting python.elc to avoid loading it
on startup (maybe there's a simpler way of preventing that?). The new
profiler report is attached.

Another detail: This doesn't happen in the ordinary python-mode, only in
inferior-python-mode.

       47639  95% - python-shell-font-lock-post-command-hook
       47639  95%  - let
       47639  95%   - if
       47639  95%    - progn
       47635  95%     - let*
       47627  95%      - let
       47623  95%       - save-current-buffer
       47623  95%        - save-current-buffer
       47615  95%         - let
       47611  95%          - if
       47611  95%           - funcall
       47611  95%            - font-lock-ensure
       47611  95%             - #<compiled -0x15f49b30cf8ae947>
       47611  95%              - font-lock-fontify-region
       47611  95%               - font-lock-default-fontify-region
       47400  94%                - font-lock-fontify-syntactically-region
       47400  94%                 - python-font-lock-syntactic-face-function
       47400  94%                  - if
       47400  94%                   - if
       47399  94%                    - python-info-docstring-p
       47387  94%                     - save-excursion
       47096  94%                      - python-nav-beginning-of-statement
       47072  94%                       - let*
       44158  88%                        - cond
       44151  88%                         - python-nav-beginning-of-statement
       44127  88%                          - let*
       41183  82%                           - cond
       41175  82%                            - python-nav-beginning-of-statement
       41133  82%                             - let*
       38429  76%                              - cond
       38421  76%                               - python-nav-beginning-of-statement
       38409  76%                                - let*
       35842  71%                                 - cond
       35838  71%                                  - python-nav-beginning-of-statement
       35806  71%                                   - let*
       33257  66%                                    - cond
       33177  66%                                     - python-nav-beginning-of-statement
       32662  65%                                      - let*
       32414  64%                                         syntax-ppss
         124   0%                                         cond
          20   0%                                         or
          76   0%                                     - save-excursion
          68   0%                                      - python-info-line-ends-backslash-p
          64   0%                                       - save-excursion
          56   0%                                        - while
          56   0%                                         - and
          56   0%                                          - nth
          56   0%                                           - or
          52   0%                                              syntax-ppss
        2525   5%                                    - syntax-ppss
          12   0%                                       #<compiled 0xb89c315bc3a37ea>
          20   0%                                    - or
           8   0%                                       nth
           8   0%                                     - let
           4   0%                                        and
        2551   5%                                   syntax-ppss
           4   0%                                 - or
           4   0%                                    nth
        2672   5%                              - syntax-ppss
           4   0%                                 #<compiled 0xb89c315bc3a37ea>
           4   0%                                or
           4   0%                            - save-excursion
           4   0%                             - python-info-line-ends-backslash-p
           4   0%                              - save-excursion
           4   0%                               - while
           4   0%                                - and
           4   0%                                 - nth
           4   0%                                  - or
           4   0%                                     syntax-ppss
        2916   5%                           - syntax-ppss
           4   0%                              #<compiled 0xb89c315bc3a37ea>
           8   0%                           - or
           4   0%                              nth
        2886   5%                          syntax-ppss
           4   0%                        - or
           4   0%                           nth
         271   0%                      - let
         217   0%                       - if
         213   0%                        - and
         173   0%                         - not
         169   0%                          - python-info-assignment-statement-p
         165   0%                           - save-excursion
         165   0%                            - let
         137   0%                             - if
         133   0%                              - python-nav-beginning-of-statement
         113   0%                               - let*
          77   0%                                - cond
          65   0%                                 - save-excursion
          61   0%                                  - python-info-line-ends-backslash-p
          48   0%                                   - save-excursion
          36   0%                                    - while
          32   0%                                     - and
          28   0%                                      - nth
          28   0%                                       - or
          28   0%                                          syntax-ppss
           8   0%                                    - if
           4   0%                                       equal
          24   0%                                  syntax-ppss
           8   0%                                  or
          20   0%                             - while
          20   0%                              - and
           8   0%                                 re-search-forward
          24   0%                           looking-at-p
           4   0%                         concat
           8   0%                        if
          84   0%                - font-lock-fontify-keywords-region
          84   0%                 - #<lambda -0xaef49294dba7a2c>
          84   0%                  - let
           4   0%                   - if
           4   0%                    - or
           4   0%                     - nth
           4   0%                      - or
           4   0%                         syntax-ppss
           8   0%         - if
           8   0%          - progn
           8   0%           - font-lock-mode
           8   0%            - font-lock-default-function
           8   0%             - font-lock-mode-internal
           8   0%              - font-lock-unfontify-buffer
           8   0%               - font-lock-default-unfontify-buffer
           8   0%                  font-lock-unfontify-region
           4   0%         python-shell-get-process-or-error
           8   0%      - while
           8   0%       - let*
           4   0%          or
           4   0%          set-text-properties
        2364   4% + ...
          47   0% + command-execute
           3   0% + redisplay_internal (C function)