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

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

The following recipe makes Emacs freeze, starting from 'emacs -Q':

1. Type 'M-x run-python RET'.

2. In the inferior-python-mode buffer that pops up, insert the following:

{
    "foo-1": "bar-1",
    "foo-2": "bar-2",
    "foo-3": "bar-3",
    "foo-4": "bar-4",
    "foo-5": "bar-5",
    "foo-6": "bar-6",
    "foo-7": "bar-7",
    "foo-8": "bar-8",
    "foo-9": "bar-9",
}

3. Navigate up and down inside this structure by running 'next-line' and
   'previous-line' in quick succession, alternating between them.

4. The movement appears slower and slower, eventually freezing up Emacs.

I've observed this in Emacs 27.2 as well, so it doesn't seem new to
Emacs 28.

Here's the report from a quick profiling I did in Emacs 28:

13447  94% - python-shell-font-lock-post-command-hook
13444  94%  - font-lock-ensure
13444  94%   - #<compiled -0x19f3968dc99b6307>
13444  94%    - font-lock-fontify-region
13444  94%     - font-lock-default-fontify-region
13420  94%      - font-lock-fontify-syntactically-region
13420  94%       - python-font-lock-syntactic-face-function
13412  94%        - python-info-docstring-p
13396  94%         + python-nav-beginning-of-statement
    4   0%         + python-info-assignment-statement-p
    8   0%      + font-lock-fontify-keywords-region
    3   0%  + font-lock-mode
  529   3% + ...
  183   1% + command-execute