9

Yesterday, I :q'd Vim to try Emacs for a while. I've started using Elisp (which is a hundred times better than VimScript), but even when I first installed it (via yum), and had changed nothing, it took about 30 seconds to start, and still does (both GUI and -nw).

I checked the *Messages* buffer:

Loading /usr/share/emacs/site-lisp/site-start.d/desktop-entry-mode-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/rpmdev-init.el (source)...done

The files seem to be specific to the RPM package I installed. I tried changing their names, yet there was no difference. It still takes 30 seconds.

I've solved it partially by never exiting emacs (I only suspend it) and trying to do everything in it, but it would be nice to occasionally open two Emacs's, especially since I have a tendency to use my terminal emulator's split function rather than something like tmux.

I realized that Emacs would load slower than Vim, but this seems ridiculous for a fresh install. Has anybody got any idea what's going on?

Thanks!

jocap
  • 477
  • 4
  • 9
  • 2
    A lot of Emacs users in fact start Emacs once per session; you can open as many frames as you like (start `emacs -d` when you log in and run `emacsclient` to edit a file). But 30s startup time is not normal; you have a package doing something weird. Does `emacs -q` load quickly? If not, looking at the *Messages* buffer, which init file is taking a long time? Where did you get Emacs from (which distribution's package), and where does the slow init file come from? – Gilles 'SO- stop being evil' May 12 '14 at 22:32
  • `emacs -q` is not faster. Removing both init files doesn't solve it. I installed it using `yum install emacs`, simply. It's called `emacs.x86_64`, `1:24.3-11.fc19` according to `yum`. – jocap May 12 '14 at 23:15
  • 5
    Oh, sorry, I should have asked: is `emacs -Q` faster? (`-q` doesn't load your personal init file, `-Q` doesn't load the system init file either.) If it is (and I suspect it is), one of the system packages is the culprit. If not, this calls for a bigger gun. Run `strace -tt -o emacs.strace emacs -q -nw` and post the trace. (This can be useful even if it's a system package that's pausing so long.) – Gilles 'SO- stop being evil' May 12 '14 at 23:23
  • To give you a point of reference on Mac, `emacs -Q` starts up under 0.05 seconds. "My" `emacs` fully configured starts up under 3 seconds. – event_jr May 13 '14 at 00:44
  • Yeah, `emacs -Q` takes about as long. So it isn't the system init file. – jocap May 13 '14 at 17:17
  • Interestingly, `(emacs-init-time)` returns 0.1 seconds. – jocap May 13 '14 at 17:30
  • Oh, just realized I never posted the trace: http://pastebin.com/raw.php?i=jPUmHQg1. The `poll()`'s at 20:44:15 through 20:44:40 take about 3-5 seconds each. – jocap May 13 '14 at 18:46
  • 1
    Oh, I just had a huge realization. When I start my computer, I currently have to run `dhclient em1` manually before I get access to the internet. Today, though, I started Emacs before, and it loaded really quickly, in a matter of seconds. Some time after I ran the command, I tried launching Emacs again and it was slow again. I'm not 100% sure that that's the cause, but it seems so. I'll reboot and try again. – jocap May 15 '14 at 16:58
  • There, I rebooted and `dhclient em1` is indeed the cause, so it definitely has something to do with the network. Is there any way to revert `dhclient em1`? – jocap May 15 '14 at 17:08
  • Found it. Added as an answer. – jocap May 15 '14 at 17:20
  • Putting your FQDN to /etc/hosts does not _solve_ the problem. The host is connected using DHCP by operators running DSL or 4G. Whenever I do see startup taking long time I'll ctrl+c and start vi. Because most of the jobs with emacs are tiny editing and within 15 seconds the work is done. Still hate vi, but it is much quicker. Searching for better solution or even patch to fix this. Have hundreds of instances. Really guys, fix this! (maybe the fix is Ansible ;-) – Kaarlo Rotten May 05 '17 at 07:32

3 Answers3

14

Emacs's PROBLEM file says:

*** Emacs startup on GNU/Linux systems (and possibly other systems) is slow.

This can happen if the system is misconfigured and Emacs can't get the
full qualified domain name, FQDN.  You should have your FQDN in the
/etc/hosts file, something like this:

127.0.0.1   localhost
129.187.137.82  nuc04.t30.physik.tu-muenchen.de nuc04

The way to set this up may vary on non-GNU systems.

This "slow startup" typically comes from a timeout, and 30s sounds about right.

As a side note: the DNS lookup that causes this slow down was considered important/useful back in the days where (almost) all machines had a static IP address. Nowadays the info gathered this way does not justify the effort, so starting with Emacs-25, Emacs does not perform this DNS lookup, so this problem should simply not exist any more.

Stefan
  • 27,908
  • 4
  • 53
  • 82
  • There doesn't appear to be any problems with /etc/hosts. It says: `127.0.0.1 localhost.localdomain localhost` `::1 localhost6.localdomain6 localhost6`. I changed it to yours, didn't help. – jocap May 13 '14 at 17:25
  • Stefan is correct. if the command `hostname -f` returns a value, then your fully qualified domain name is set up, and emacs will start up quickly. – Gabe Apr 15 '16 at 17:21
1

Okay, I have a (quirky and temporary) solution. I have to run dhclient em1 to access the internet, which makes Emacs take 30 seconds to load, probably because of some timeout. So, having already run dhclient em1, I use a shell script to launch Emacs that does the following:

sudo pkill dhclient
sudo ifconfig em1 down
emacs -nw -daemon 2> /dev/null
sudo ifconfig em1 up
sudo dhclient em1

That disables networking, launches Emacs as a daemon, and re-enables networking. It's ugly, but it works for now. If anybody else has a better answer, I'd be happy to hear it. Of course, em1 would have to be replaced by your Ethernet device (probably eth0, I guess).

jocap
  • 477
  • 4
  • 9
1

I had a smilar problem with emacs taking about 15 seconds for startup. In my case the reason was a DNS timeout. For some reason, with my dormitory DNS, a failed reverse lookup (host 127.0.0.1) takes about 10 seconds. Replacing the DNS server by the google nameserver (8.8.8.8) produces an almost instant "not found: 3(NXDOMAIN)" response. At the same time, emacs's startup time went down to less than 2 seconds. Thanks @Stefan who pointed me into the direction of DNS problems.

Edit: adding the google nameserver as additional NS in Network Manager also does the job. (i.e. when your resolv.conf has the NSs in this order:

nameserver a.b.c.d
nameserver 8.8.8.8

)

lambda.xy.x
  • 4,918
  • 24
  • 35