John Smith's Blog

Ramblings (mostly) about technical stuff

Fixing slow emacs startup on Linux under VMWare

Posted by John Smith on

TL; DR: try adding the host name to /etc/hosts

For various reasons I can't be bothered to go into now, on an intermittent basis I end up doing a lot of development on Linux VMs on Windows - mostly Fedora on VMWare. For a while I've noticed that emacs (my editor of choice for the past 20+ years) has been intermittently very slow to start up - 10 seconds plus, I'd guess - taking much longer than a programs I'd assume to be much more hefty, such as web browsers or GIMP. Although I've got a few modes and other customizations in place, I wasn't aware that my emacs configuration was anything unusual, and it ran fine on "native" hardware that was much slower or lacking in RAM than my VMs.

Anyway, I finally decided to get off my backside and find out what the problem was, and ideally fix it... Googling for variants of emacs vmware slow startup failed to find anything useful - which is my main motivation for writing this up.

The first thing I tried was some basic profiling of the startup, as per tip #5 found here. This wasn't of any help though, telling me that .emacs was loaded in 0 seconds, which might have been reasonably true, but certainly wasn't anything like the real-world time between entering emacs myfile.txt and an editor window popping up.

Next thing I tried was a tip from an Ubuntu forum, but again this had no noticeable effect. I was about to try compiling all my .el files to be .elcs, but then it struck me that it might be worth trying a different angle of attack...

It's been quite a while since I last used strace, or similar tools such as , truss, etc - and certainly I've rarely used it on programs that I haven't written the original source code for. However, if this showed the process hanging on a particular system call, then that would certainly go a long way to understanding what was happening.

Unfortunately, I don't have the output to cut'n'paste here, but it was immediately apparent that something related to the hostname could be the cause - the process was hanging on poll() calls, and a couple of lines further up in the logging were references to the host name. My initial suspicion was that maybe it was something related to hostname lookups?

A quick viewing of /etc/hosts showed that there were only entries for localhost and variations - there were none for the real host name. The VM was configured to acquire a dynamic IP via DHCP, but I decided to me a naughtly boy and quickly hack the IP and hostname into /etc/hosts to test the theory. Lo and behold, emacs suddenly popped into life almost immediately!

I can't believe that the VMWare DNS server is so slow as to be the cause of this problem, but now that I have the desired end-result, I'm not wasting any more time on it. I tidied up my mess, by reconfiguring the OS in the VM to have a static address rather than a dynamic one, and all is now fine.

In retrospect, this static/dynamic difference probably explains why I'd experienced the problem intermittently over time - most of my VMs are just for testing, and don't have much configuration from the default, whereas any VM that I use for "real work" will almost certainly have been given a static IP so that I can more easily access it from the host OS.

About this blog

This blog (mostly) covers technology and software development.

Note: I've recently ported the content from my old blog hosted on Google App Engine using some custom code I wrote, to a static site built using Pelican. I've put in place various URL manipulation rules in the webserver config to try to support the old URLs, but it's likely that I've missed some (probably meta ones related to pagination or tagging), so apologies for any 404 errors that you get served.

RSS icon, courtesy of www.feedicons.com RSS feed for this blog

About the author

I'm a software developer who's worked with a variety of platforms and technologies over the past couple of decades, but for the past 7 or so years I've focussed on web development. Whilst I've always nominally been a "full-stack" developer, I feel more attachment to the back-end side of things.

I'm a web developer for a London-based equities exchange. I've worked at organizations such as News Corporation and Google and BATS Global Markets. Projects I've been involved in have been covered in outlets such as The Guardian, The Telegraph, the Financial Times, The Register and TechCrunch.

Twitter | LinkedIn | GitHub | My CV | Mail

Popular tags

Other sites I've built or been involved with

Work

Most of these have changed quite a bit since my involvement in them...

Personal/fun/experimentation