4 ms·
I just disable emacs garbage collection entirely. Fast startup, no more random pauses, haven't noticed any problems yet. (This was probably like a year ago.) (
by dilap 4y ago
I just disable emacs garbage collection entirely. Fast startup, no more random pauses, haven't noticed any problems yet. (This was probably like a year ago.)
(On the other hand, emacs is never quite problem free, so maybe this is introducing problems and I just haven't noticed.)
I have tons of customizations and lots of packages, but be as religious as reasonable about lazy loading.
$ time emacs --eval '(save-buffers-kill-emacs)'
real 0.21s
Not bad, but still very noticable, which is annoying.
About half of it is unavoidable.
$ time emacs -q --eval '(save-buffers-kill-emacs)'
real 0.11s
(-q disables reading the config file.)
(With default GC settings, startup is about 300ms.)
- matthews2 4y agoInstead of totally killing the garbage collector, you can effectively turn it off during startup by setting gc-cons-threshold to a large number, and then restore it after init. The article touches on this but they don't increase it very much and restore it at the end of init.el (emacs-startup-hook runs later). early-init.el: (setq gc-cons-threshold most-positive-fixnum) (add-hook 'emacs-startup-hook (lambda () (setq gc-cons-threshold (* 2 1024 1024))))
- dilap 4y agoIt was subtle in my message, but my other reason for disabling was to avoid random collection pauses when using emacs. A sibling poster recommended GCing on deactivate, which is an interesting idea! But again, I truly haven't been able to notice any ill effects of not GCing. I tend to probably leave emacs open for maybe a few hours at a time, so I guess in that sense I'm manually GCing. :-)
- matthews2 4y agoNot running the GC at all is certainly interesting though :) Have you tried running 'M-x memory-report' before quitting to see how much memory you ended up using?
- dilap 4y agoMy emacs ain't new enough to have memory-report. I tried just running memory-report.el from HEAD, but it errored out (after hanging emacs for like 3 mins!). Anyway, here's the poor man's version: cons-cells-consed is 38315202 There's probably some roughly accurate map from that to number of bytes of memory allocated, I will take a totally random guess it's 10, which would give 383MB of memory used. I'm at half a day of usage, so figure 800MB by end of day. 16GB machine, so you can see why my "garbage collect once a day before bed" strategy is working out ;-). (Plus also I wonder how much of the uncollected garbage just gets paged out by the OS and never touched again.)
- thom 4y agoI like to do this to ensure GC happens occasionally, when I focus away from Emacs: (add-function :after after-focus-change-function (lambda () (unless (frame-focus-state) (garbage-collect))))
- dilap 4y agoAh, neat idea! Thanks!