Commit 5bf0ed33 authored by Stuart Hickinbottom's avatar Stuart Hickinbottom
Browse files

Prevent duplicate idle timers being created

I found that when combined with desktop-save-mode, upon session
reloading in a new Emacs instance, then gcmh-mode would be enabled
multiple times even when it was already active. This causes multiple
duplicate idle timers to be created (one for each time the mode is

The same effect can be provoked by manually running (gcmh-mode t)
multiple times.

The effect of this is garbage collection being executed multiple times
each time the idle time expired.

I noticed this because GC was slower than expected, and turning on
gcmh-verbose revealed all those duplicate GC events each time Emacs
had been idle.

This change simply removes any extant timer before enabling the mode
so we're guaranteed to only have one or zero idle timers defined.
parent 1953d913
......@@ -86,6 +86,10 @@ This is to be used with the `pre-command-hook'."
"Minor mode to tweak Garbage Collection strategy."
:lighter " GCMH"
:global t
;; Cancel any pending timer (prevents duplicate idle timers).
(when (timerp gcmh-idle-timer)
(cancel-timer gcmh-idle-timer))
(if gcmh-mode
(setq gc-cons-threshold gcmh-high-cons-threshold
......@@ -94,7 +98,6 @@ This is to be used with the `pre-command-hook'."
;; Release severe GC strategy before the user restart to working
(add-hook 'pre-command-hook #'gcmh-set-high-threshold))
(cancel-timer gcmh-idle-timer)
(setq gc-cons-threshold gcmh-low-cons-threshold
gcmh-idle-timer nil)
(remove-hook 'pre-command-hook #'gcmh-set-high-threshold)))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment