abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.3k stars 338 forks source link

Severe slowdown in larger files after using counsel-outline in emacs 29.3 #3050

Closed kings2u closed 2 months ago

kings2u commented 3 months ago

I recently upgraded from emacs 28.2 to 29.3. When I resumed working in a large 11MB org-mode file that never gave me problems with speed on 28.2, I noticed a severe slowdown when editing the buffer after invoking counsel-outline. It took a while for me to isolate the issue, but it seems to be caused by the many markers that this command creates in the buffer.

Here are the steps to reproduce the issue:

  1. Start emacs 29.3 with emacs -q to ensure a clean environment.
  2. Paste this minimal config into the scratch buffer and eval-buffer.
  3. Open the following file in org-mode.
  4. goto-line 35.
  5. Invoke counsel-outline and simply press enter to navigate point to the headline at line 34.
  6. Go to the end of the line and press enter to start typing on a new line at line 35.
  7. Start typing n space, or t space several times very fast and observe how long it takes for the abbrev expansions (defined in the minimal config above) to show up on the screen.

To verify this slowdown doesn’t occur before invoking counsel-outline, you can try doing Step 7 after Step 4 and see how fast the abbrevs expand. You can also repeat Steps 1 through 7 above but with emacs -q using emacs version 28.2 and see that no slowdown occurs at Step 7.

Using emacs 29.3, when I use profiler-start (CPU) between Steps 4 and 5, and then profiler-stop after Step 7, I get a very big entry (e.g., 70%) for redisplay_internal (C function) in the profiler-report. Using the profiler at the same steps using emacs 28.2, I don’t get a big entry for redisplay_internal (C function).

This slowdown even in emacs 29.3 only seems to occur with larger files like the test file. I’ve tried many different setups to avoid the problem, including different versions of org-mode, but the only thing that solves it is going back to emacs 28.2, which apparently handles markers more efficiently. The only way to solve the problem within emacs 29.3 I’ve found is to use a different version of counsel-outline that gets rid of all the markers it creates, as suggested here. The specific modifications I use can be found here (I eval these functions after I’ve loaded counsel).

My tentative conclusion is that this slowdown is NOT a bug with counsel but rather in emacs 29.3, but I wanted to make sure before I report the bug to emacs developers. I have noticed a similar slowdown when editing the test file after invoking org-refile when org-refile-use-cache is set to t, and my understanding is that org-refile-use-cache will also make org-refile create a ton of markers in the buffer.

Even if this is an issue with 29.3, it might still be worth it to create a user option in counsel to turn off the creation of markers by counsel-outline. Even though that might render ivy-resume ineffective regarding counsel-outline, that is worth the tradeoff for some of us.

Thank you so much!

basil-conto commented 2 months ago

For posterity, this is linked to Emacs bugs bug#63040 and bug#71644, which were recently fixed upstream.

kings2u commented 2 months ago

Those bug fixes seem to have solved it, thank you!