Bozhidar Batsov has posted another in his long list of informative Emacs posts. This time, it’s about configuring Emacs garbage collection. The principal way of doing that is to set gc-cons-threshold
to a higher value than its default of 80000. Batsov has his set to 50000000 and is wondering if he should increase it.
On the other hand, picking a correct value is far from trivial. Batsov includes some text from Eli Zaretskii, the current Emacs maintainer, that says setting the value too high will adversely affect performance.
Garbage collection is notoriously difficult to configure correctly in any application and I have no special insight into what the correct value should be in any particular situation. What I can do, though, is tell you what I do, which works very well for me. I virtually never see a pause for garbage collection. On the other hand, I don’t invoke a lot of memory hungry functions so my results may differ from yours.
I long ago gave up tweaking gc-cons-threshold
and installed gcmh to handle garbage collection for me. Gcmh is based on the observation that if Emacs has been idle for 15 seconds, it will probably be idle longer so it’s a good time kick off garbage collection. It does this by setting the normal threshold very high but when it sees that Emacs is idle, it sets it to a low value to kick off garbage collection. The explanation of how it works is here.
Gcmh tells you every time it kicks off garbage collection and I frequently see this when I stop typing for a bit. The system works really well for me. As I say, I never see a delay for garbage collection. If you’re seeing problems in that area, give gcmh a try and see how it works for you.