Small white is a loyal user of Emacs, on the CentOS server also need to compile and install a Emacs for their own use. Because of the use of a lot of Emacs plug-ins, each time it is very slow to start, almost 5s or so to open a file (let everyone mistakenly think server configuration sucks it). In the speed of opening the file with Vim some gap, vim open file is almost 0 waiting (my vim here is simple configuration, and do not use the extra plug-ins; use Emacs's peers do not scold me OH).
Emacs has recently been found to be extremely slow to open, with no such problem. Think about it, mainly before there is network connection, and this is not the network connection several times. So little white just want to be Emacs what plug-ins need to use the network? So using the system under the Strace tool to track how Emacs started, and finally find out what is the reason, the original is the host name resolution problem,
How slow is it to start up without the Internet?
[Email protected] ~]# time Emacs--killreal0m5.402suser0m0.367ssys0m0.019s
Take a look at the partial output of strace Emacs,
# strace emacs.......open ("/etc/hosts", o_rdonly| O_CLOEXEC) = 3 # will first look at the/etc/hosts file, not found in the Hosts file about the system hostname parsing FCNTL (3, F_GETFD) = 0x1 (flags fd_cloexec) fstat (3, {st_mode=s_ifreg|0644,  ST_SIZE=338,&NBSP, ...}) = 0mmap (null, 4096, prot_read| prot_write, map_private| map_anonymous, -1, 0) = 0x7fa6ae5a3000read (3, "127.0.0.1 Localhost.localdomai "..., 4096) = 338read (3, " ", 4096) = 0close (3) &nBsp; = 0munmap (0x7fa6ae5a3000, 4096) = 0open ("/etc/ld.so.cache", o_rdonly) = 3fstat (3, {st_mode=s_ifreg|0644, st_size=49825, ...}) = 0mmap (null, 49825, prot_read, map_private, 3, 0) = 0x7fa6ae597000close (3) = 0open ("/lib64/libnss_dns.so.2", o_rdonly) = 3read (3, "\177elf\2\1\1\0\0\0\0\0\0\0\0\ 0\3\0>\0\1\0\0\0\0\20\0\0\0\0\0\0 "..., 832) = 832fstat (3, {st_mode=s_ifreg|0755, ST_SIZE=27424,&NBSP, ...}) = 0mmap (null, 2117880, prot_read| prot_exec, map_private| map_denywrite, 3, 0) = 0x7fa6a7483000mprotect (0x7fa6a7488000, 2093056, prot_none) = 0mmap (0x7fa6a7687000, 8192, prot_read| prot_write, map_private| map_fixed| map_denywrite, 3, 0x4000) = 0x7fa6a7687000close (3) = 0open ("/lib64/libresolv.so.2", O_RDONLY) = 3read (3, "\177elf\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\00009\0\0\0\0\0\0" ..., 832) = 832fstat (3, {st_mode=s_ifreg|0755, st_size=110960, ...}) = 0mmap (null, 2202248, prot_read| prot_exec, map_private| map_denywrite, 3, 0) = 0x7fa6a7269000mprotect (0x7fa6a727f000, 2097152, prot_none ) = 0mmap (0x7fa6a747f000, 8192, prot_read| prot_write, map_private| map_fixed| map_denywrite, 3, 0x16000) = 0x7fa6a747f000Mmap (0x7fa6a7481000, 6792, prot_read| prot_write, map_private| map_fixed| map_anonymous, -1, 0) = 0x7fa6a7481000close (3) = 0mprotect (0x7fa6a747f000, 4096, prot_read) = 0mprotect (0x7fa6a7687000, 4096, prot_read) = 0munmap (0x7fa6ae597000, 49825) = 0socket (PF_INET, SOCK_DGRAM| SOCK_NONBLOCK, IPPROTO_IP) = 3connect (3, {sa_family=af_inet, sin_port=htons (53),  SIN_ADDR=INET_ADDR ("127.0.0.1")}, 16) = 0 # then connect the local 53 port for domain name resolution, then SendTo system call appears " Connection refused "Error Poll ([{fd=3, events=pollout}], 1, 0) = 1 ([{fd=3, revents=pollout}]) SendTo (3, "W\265\1\0\0\1\0\0\0\0\0\0\10mydevops\0\0\1\0\1 ", 26, msg_nosignal, null, 0) = 26poll ([{fd=3, events=pollin| pollout}], 1, 5000) = 1 ([{fd=3, revents=pollout| Pollerr}]) sendto (3, "\32\205\1\0\0\1\0\0\0\0\0\0\10mydevops\0\0\34\0\1", 26, msg_nosignal, null, 0) = -1 ECONNREFUSED (connection refused) Close (3) = 0socket (PF_INET, SOCK_DGRAM| SOCK_NONBLOCK, IPPROTO_IP) = 3connect (3, {sa_family=af_inet, sin_port=htons (53),  SIN_ADDR=INET_ADDR ("127.0.0.1")}, 16) = 0poll ([{fd=3, events=pollout}], 1, 0) = 1 ([{fd=3, revents=pollout}]) sendto (3, "w\265\1\0\0\1\0\ 0\0\0\0\0\10mydevops\0\0\1\0\1 ", 26, msg_nosignal, null, 0) = 26poll ([{fd=3, events=pollin| pollout}], 1, 5000) = 1 ([{fd=3, revents=pollout| Pollerr}]) sendto (3, "\32\205\1\0\0\1\0\0\0\0\0\0\10mydevops\0\0\34\0\1", 26, msg_nosignal, null, 0) = -1 ECONNREFUSED (connection refused) Close (3)
You can see that there are many "Connection refused" error messages, which consume a lot of time in these steps, resulting in a final timeout. Do not know why Emacs will parse this information when it is started?
Now that the problem has arisen, the solution here is to add the/etc/hosts file with the host name resolution. Sure enough, the problem is solved. It is also fast to open files in emacsclient by using Emacs daemon mode.
After you have added host name resolution in/etc/hosts, the time to open Emacs is:
[Email protected] ~]# time Emacs--killreal0m0.400suser0m0.378ssys0m0.019s
is not a lot of difference.
Finally, about the start-up speed of Emacs, Little white here summarizes 3 ways:
Emacs starts in Daemon (supported from the EMACS23 version), and then uses Emacslient to edit the file, which is opened almost seconds.
# How to Manipulate # Emacs--daemon # First start with daemon # emacsclient/etc/hosts # then you can edit the file
Set system hostname resolution in/etc/hosts
# Hostnamemydevopsecho "192.168.56.101 mydevops" >>/etc/hosts
Do not load any profiles for startup (the more customized the content, the slower it starts)
This article is from the "solid-state Drive" blog, make sure to keep this source http://lavenliu.blog.51cto.com/5060944/1755557
Resolves an issue in which Emacs startup is slow due to DNS parsing