user2746900
user2746900

Reputation: 61

Emacs hanging every 5 seconds with many buffers open

I'm running into an issue where having many buffers open results in emacs briefly hanging exactly every 5 seconds while typing into a buffer. I prefer to have these buffers open for use of https://github.com/alphapapa/org-rifle - but I've confirmed that reducing the number of open buffers makes this issue not noticeable.

I've tried changing auto save by setting auto-save-interval to a large number, as well as enabling auto-save-visited-mode. I also turned off company-mode and org-evil. None of these have made a difference.

Running a cpu/mem profile didn't reveal anything interesting, unless I'm missing something: Memory:

  1 + timer-event-handler                                     103,073,519  53%
  1 + command-execute                                          42,896,933  22%
  2 + company-post-command                                     28,962,855  14%
  3 + redisplay_internal (C function)                          13,816,595   7%
  4 + org-evil--post-command                                    5,206,152   2%
  5 + evil-repeat-post-hook                                        55,576   0%
  6 + evil-repeat-pre-hook                                          5,184   0%
  7   evil--jump-handle-buffer-crossing                             2,112   0%
  8 + undo-auto--add-boundary                                       1,056   0%
  9 + evil-esc                                                        192   0%
 10 + eldoc-schedule-timer                                             48   0%
 11   ...                                                               0   0%

CPU:

  1 + timer-event-handler                                            2594  71%
  1 + command-execute                                                 730  20%
  2 + ...                                                             200   5%
  3 + company-post-command                                             53   1%
  4 + redisplay_internal (C function)                                  41   1%
  5 + org-evil--post-command                                           17   0%
  6 + evil-repeat-post-hook                                             1   0%
  7 + evil--jump-hook                                                   1   0%

My dot emacs config is https://github.com/esmongeski/dotfiles/blob/main/dotEmacs.org

What else can I do to diagnose this type of lag?

Upvotes: 2

Views: 200

Answers (1)

user2746900
user2746900

Reputation: 61

This was caused by garbage collection - https://www.gnu.org/software/emacs/manual/html_node/elisp/Garbage-Collection.html#:~:text=Emacs%20provides%20a%20garbage%20collector,still%20accessible%20to%20Lisp%20programs has details on how to tune it.

Update - I was on emacs 27.x, and upgrading to 28.x fixed up the lag with the memory leak.

Upvotes: 1

Related Questions