» speeding up emacs saves

Friday, 11 March A.D. 2011 @ 9:12 PM

For a while now, I've noticed that saving files (maybe loading files, but saving files especially) was ridiculously slow in emacs. The busy cursor would come up for a good second or two when saving files. For a while I attributed it to the hard drive noticeably spinning up on my laptop (which it's doing now as I write this), but then I noticed--or got really annoyed--by the same behavior on my desktop. Particularly when editing files in a GCC git checkout, though I think it happened to other files as well.

Investigating, I could tell via strace that emacs was spinning off several processes (!) every time I saved a file. I tried using edebug, but that didn't seem to be working. (Somebody suggested that the routines I was trying to trace might be called directly from the C code in emacs and not go through whatever hooks edebug inserts into the system. This explanation sounds plausible, though quite unusual for emacs.) Finally some kind soul--cmm, I think--on #sbcl, where I ranted about this, suggested inserting:

(setq vc-handled-backends nil)

into my .emacs. Wow. It was like getting a computer upgrade, perhaps as radical of a change as an SSD might be; saves were now lightning fast compared to their prior speed.

I haven't poked into emacs's source code to see what was going on. And the puzzling thing is that this doesn't seem to be a consistent problem; James Knight/foom told me that he was dealing with large-ish git repos, as I was, and VC wasn't causing him any heartache. And clearly other emacs users aren't having similar problems--or perhaps everybody's silenty disabling VC and using more performant solutions. I did find a similar story to my own, but only with searching for vc-handled-backends explicitly, rather than other search terms (“slow,” “saving,” etc.).

So, hopefully search engines pick this post up and other afflicted people will find this solution and rejoice. Even better, somebody more knowledgeable about emacs than I will tell me what was really going on...