3 ms·
Instead 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 restor
by matthews2 4y ago
Instead 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.)