DarwinAwardWinner/ido-completing-read-plus

Slow scrolling seemly caused by ido-completing-read

ccakes opened this issue · 2 comments

I'm on Emacs 28 master with native-comp so this might be a bit of a bleeding edge case but worth asking about.

Scrolling in some buffers feels extremely slow and pegs the CPU, but others is fine. org-mode is fine, go-mode with lsp-mode and gopls is very sluggish. Enabling the profiler and just scrolling ~50 lines down an open buffer gives me this:

Samples     %    Function
         393  75% - command-execute
         393  75%  - call-interactively
         393  75%   - apply
         393  75%    - call-interactively@ido-cr+-record-current-command
         393  75%     - #<subr call-interactively>
         393  75%      - funcall-interactively
         389  74%       - amx
         389  74%        - amx-read-and-run
         377  72%         - amx-completing-read
         377  72%          - amx-completing-read-auto
         377  72%           - amx-completing-read
         376  72%            - amx-completing-read-ido
         376  72%             - ido-completing-read+
         373  71%              - ido-completing-read
         373  71%               - apply
         373  71%                - ido-completing-read@ido-cr+-replace
         373  71%                 - #<subr ido-completing-read>
         373  71%                  - ido-read-internal
         373  71%                   - apply
         373  71%                    - ad-Advice-ido-read-internal
         373  71%                     - #<subr ido-read-internal>
         318  61%                      - read-from-minibuffer
          70  13%                       + timer-event-handler
          51   9%                       + ido-exhibit
           4   0%                       + redisplay_internal (C function)
           1   0%                         ido-cr+-schedule-dynamic-collection-update
           2   0%              + #<compiled 0x189a5f324cedffe8>
           7   1%         + amx-augment-commands-with-keybinds
           3   0%         + execute-extended-command
           1   0%         + amx-make-keybind-hash
           4   0%       + evil-next-line
          47   9% + redisplay_internal (C function)
          45   8% + ...
          35   6% + lsp-ui-doc--make-request

Any ideas on where I can start digging? It feels like a side effect since I can't think why completing-read would even be being triggered on a next-line but 🤷

Hmm, the presence of amx in the call stack implies that you might be capturing a lot of work that Emacs is doing while executing M-x. I'm guessing you did something like M-x profiler-stop at the end? Can you instead try executing something like this using M-x eval-expression? That way, there should be no usage of M-x during profiling.

(progn
  (profiler-start 'cpu)
  (dotimes (x 100)
    (next-line)
    (redisplay))
  (profiler-stop)
  (profiler-report))

Alternatively, you could stick this code in a command and run it directly with M-x. Here's what I get when I run it:

- command-execute                                                 593  96%
 - call-interactively                                             593  96%
  - apply                                                         593  96%
   - call-interactively@ido-cr+-record-current-command            593  96%
    - apply                                                       593  96%
     - #<subr call-interactively>                                 593  96%
      - funcall-interactively                                     593  96%
       - eval-expression                                          593  96%
        - apply                                                   593  96%
         - #<compiled 0x4429db95>                                 593  96%
          - eval                                                  593  96%
           - progn                                                593  96%
            - let                                                 593  96%
             - while                                              593  96%
              - let                                               593  96%
               - next-line                                        147  23%
                - apply                                           147  23%
                 - ad-Advice-next-line                            147  23%
                  - #<compiled 0x44271f9d>                        147  23%
                   - line-move                                    147  23%
                    - line-move-visual                            141  22%
                     + posn-at-point                                5   0%
               + redisplay                                         67  10%
- ...                                                              21   3%
   Automatic GC                                                    21   3%

🤦

Thanks for the tip - looks like it's definitely unrelated to this package. Thanks for the super quick help and for pointing me in the right direction! 😊

        1444 100% - command-execute
        1444 100%  - call-interactively
        1444 100%   - apply
        1444 100%    - call-interactively@ido-cr+-record-current-command
        1444 100%     - #<subr call-interactively>
        1444 100%      - funcall-interactively
        1444 100%       - eval-expression
        1444 100%        - apply
        1444 100%         - #<subr eval-expression>
        1444 100%          - progn
        1441  99%           - let
        1441  99%            - while
        1441  99%             - let
        1057  73%              - redisplay
          16   1%               - timer-event-handler
          16   1%                - apply
          15   1%                 - auto-revert-buffers
          15   1%                  - auto-revert-buffer
          15   1%                   - auto-revert-handler
          15   1%                    - vc-refresh-state
          15   1%                     - apply
          15   1%                      - #<compiled -0x29de2f0d28e0987>
          15   1%                       - apply
          15   1%                        - #<subr vc-refresh-state>
           9   0%                         - vc-backend
           9   0%                          + vc-registered
           3   0%                         + vc-mode-line
           2   0%                         + vc-call-backend
          10   0%               + redisplay_internal (C function)
         296  20%              + next-line
           3   0%           + profiler-start
           0   0% + ...