Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve "Tweaking the garbage collector" #64

Open
buhtz opened this issue Oct 14, 2021 · 1 comment
Open

improve "Tweaking the garbage collector" #64

buhtz opened this issue Oct 14, 2021 · 1 comment

Comments

@buhtz
Copy link

buhtz commented Oct 14, 2021

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
Copy link
Author

buhtz commented Nov 22, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant