emacs-from-scratch icon indicating copy to clipboard operation
emacs-from-scratch copied to clipboard

improve "Tweaking the garbage collector"

Open buhtz opened this issue 3 years ago • 1 comments

This is about this section of your great docu. https://github.com/daviwil/emacs-from-scratch/blob/master/show-notes/Emacs-Scratch-12.org#tweaking-the-garbage-collector

The default value currently is 800000. Now one knows if and when this would be modified. Wouldn't it be better to read and remember/backup the default value on the top of the init.el file and store it back at the end.

Sound simple but not for a beginner. I have no idea how to do this in Lisp.

buhtz avatar Oct 14 '21 21:10 buhtz

This is how I do this now...

In the beginning of init.el

(setq gc-cons-threshold-original gc-cons-threshold)
(setq gc-cons-threshold (* 1024 1024 300))  ; 300 MB

And at the end

;; === Reset values for startup optimzation
;; see: https://emacs.stackexchange.com/a/34367/12999
;; It is run-with-idle-timer instead of after-init-hook because "that would
;; run immediately after initialization, which might make the user wait for
;; GC. By using an idle timer, it can run when the user's not using Emacs."
(run-with-idle-timer
 5 nil
 (lambda ()
   (setq gc-cons-threshold gc-cons-threshold-original)
   (makunbound 'gc-cons-threshold-original)
   (message "gc-cons-threshold restored")))

Not sure if this is a good way. That is why I do not open it as a PR.

buhtz avatar Nov 22 '21 14:11 buhtz