lastquestion / explain-pause-mode

top, but for Emacs.
GNU General Public License v3.0
241 stars 6 forks source link

Disabling explain-pause-mode does not clear timers created while the mode is activated #90

Open yantar92 opened 4 years ago

yantar92 commented 4 years ago

The issue is in the topic. Severals dozens of timers created by explain-pause-mode appears to slow down Emacs, though clearing the timers would be a good idea regardless of this problem.

lastquestion commented 4 years ago

Did you check the timers via the list-timers command? When the mode is activated, it hooks all timers so the name of the created timers will be like explain-pause--wrap-callback. Even after you disable the mode, the functions are still wrapped. It shouldn't do anything when the mode is disabled, but the wrapper functions are still there.

So,

Are you noticing that more and more timers are created and not destroyed? Or is it rather after the mode is disabled, the timers are all still named explain-pause--wrap-callback?

lastquestion commented 4 years ago

It's also possible the code that's supposed to check to see if the mode is on or off is not working right, and that could be slowing down emacs.

But I suspect the timers created actually were created by other packages, but there's no way to tell which was which, because they are all named explain-pause--wrap-callback.

I think the first step is to introduce a new symbol for every wrapped callback that has the name of the original function in it. Also, it might be possible to unwrap all the callbacks when the mode is uninstalled. It should be possible.

lastquestion commented 4 years ago

Hm, it's possible that when the mode is re-enabled, it's wrapping already wrapped timers and that would indeed slow things down every time you enabled-re-enabled the mode. I will check on that.

yantar92 commented 4 years ago

Did you check the timers via the list-timers command?

Yes.

Even after you disable the mode, the functions are still wrapped. It shouldn't do anything when the mode is disabled, but the wrapper functions are still there.

Here is an example of relevant list-timers output. Even if the timers do nothing, they still require Emacs to process them.

        35.11      300.0    explain-pause--wrap-callback
        36.13      300.0    explain-pause--wrap-callback
        43.51       60.0    explain-pause--wrap-callback
        43.51       60.0    explain-pause--wrap-callback
  • 0.50 t explain-pause--wrap-callback
  • 1.00 t explain-pause--wrap-callback
  • 15.00 t explain-pause--wrap-callback
  • 60.00 t explain-pause--wrap-callback
  • 7200.00 - explain-pause--wrap-callback

Are you noticing that more and more timers are created and not destroyed? Or is it rather after the mode is disabled, the timers are all still named explain-pause--wrap-callback?

Both. If explain-pause-mode is enabled for a long time, the number of timers generally keep increasing. Up to the point that Emacs slows down to >0.5 sec to run self-insert-command simply because Emacs is checking if there is a need to run all those timers. Killing the timers often has an immediate effect and improves Emacs performance.