I read that changing the default garbage collector settings is not recommended https://lists.gnu.org/archive/html/help-gnu-emacs/2007-06/msg00243.html however I noticed it can make an impact on the startup speed.
I would like to prevent garbage collection only during startup then set back the GC threshold to its original value 800000
.
I added this to early-init.el:
(setq gc-cons-threshold (* 50 1000 1000))
and then I added this to init.el:
(add-hook 'emacs-startup-hook
(lambda ()
"Restore defalut values after init."
(setq gc-cons-threshold 800000)))
I can go a little bit further adding these lines into early-init.el as well:
(defvar default-file-name-handler-alist file-name-handler-alist)
(setq file-name-handler-alist nil)
Then setting the file-name-handler-alist
back to its original value in init.el
(add-hook 'emacs-startup-hook
(lambda ()
"Restore defalut values after init."
(setq file-name-handler-alist default-file-name-handler-alist)
(setq gc-cons-threshold 800000)))
This change speeds up the startup even more reducing the waiting by 2-3 seconds.
I was wondering if it is necessary to separate these in two separates file, one chunk of code going into early-init.el
and the other that sets back to original values in init.el
or is it possible to put everything in early-init.el
? In other idea, is it okay to add (add-hook 'emacs-startup-hook
in the early-init.el
file?