【问题标题】:Why is emacs slow to give the prompt为什么emacs给出提示很慢
【发布时间】:2022-01-09 02:40:41
【问题描述】:

如果我删除我的 .emacs 文件和 .emacs.d 文件夹,只是为了确保我观察到的不是由我的个人配置中的问题引起的,然后我调用 emacs foo.txt emacs 窗口打开,使用“Lisp Interaction ElDoc”保持空白至少 5 秒 写在底部栏的中心,通常指示主要模式。然后(即在几秒钟后),窗口垂直分成两部分,底部为初始屏幕,顶部为文档 foo.txt,“Lisp Interaction ElDoc”被替换为“(文本) ' 符合预期。

如果我随后关闭文档并立即调用 emacs foo.txt 再次,然后我直接获得最终窗口(一分为二,带有启动屏幕和所有内容),而不会卡在第一个状态几秒钟。

但是,如果我关闭文档并等待一段时间(一分钟左右),然后调用 emacs foo.txt 再次,emacs 窗口打开,它保持空白至少 5 秒钟,底部栏的中心写有“(基本)”,消息“正在加载 /usr/share/emacs/site-lisp/site-start .d/rpmdev-init.el... done'(如果您想知道,这是从 /usr/share/emacs/site-lisp/site-start.d/ 加载的最后一个文件)。然后,弹出文件,还有启动画面等。

*Messages* 的内容没有给我任何关于 emacs 在完成加载 rpmdev-init.el 和显示启动屏幕之间可以尝试做什么的信息(带有消息“有关 GNU Emacs 和 GNU 系统的信息,请键入 Ch钙。”)。这里是*Messages*的内容:

Loading /usr/share/emacs/site-lisp/site-start.d/auctex.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/autoconf-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/clang-format.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/clang-include-fixer.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/clang-rename.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/cmake-init.el (source)...done
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/mercurial-site-start.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/pg-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/preview-latex.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/protobuf-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/rpmdev-init.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.

这种行为(有时要等待几秒钟才能编辑文件)很烦人。我知道我可以将 emacs 作为服务器启动,以避免每次我想打开 emacs 窗口时重新加载所有内容,但是,我想了解幕后发生的事情,因为这似乎是某种异常的痕迹。所以我的问题是:有没有人知道是什么导致 emacs 有这种行为?或者关于如何着手解决的任何线索?

我尝试使用emacs -qemacs -Q 并观察到同样的现象。我在 Fedora 34 上使用 emacs 27.2。

编辑: 类似的问题经常发布在 StackOverflow 上(据我所知,在 SO 上发布的问题比在任何其他 StackExchange 网站上都多)。例如:

  • 我发现与我的问题最接近的问题是here
  • 另一个非常接近的是here(或here,只是重复)。
  • That one
  • That onethat one 似乎与我的情况无关。

通常的嫌疑人是错误的配置(此处排除,因为即使使用 -Q 也会出现问题)或错误的主机名配置(据我所知,应该在现代版本的 emacs 上修复,而且,无论如何,我的主机名是正确配置)。

我仍在尝试比较作为结果获得的痕迹emacs_slow.straceemacs_fast.strace

strace -tt -o emacs_slow.strace emacs foo.txt -eval '(kill-emacs)' && \ 
strace -tt -o emacs_fast.strace emacs foo.txt -eval '(kill-emacs)'

它们都是大约 21k 行并且非常相似。如果有人知道具体要检查什么,欢迎提出建议。

【问题讨论】:

  • 这种题比较适合ServerFault或者SuperUser这里的Linux标签只针对编程相关的问题
  • 好的。我可以在超级用户上转发。我在这里发帖是因为我发现了许多其他关于 emacs 在 stackoverflow 上运行缓慢的问题,当我用谷歌搜索试图理解这个问题时。我放了“linux”标签,因为我在 Linux 上运行,并且由于我不知道问题的原因,我认为它可能与 Linux 有关。但我删除它,因为它不合适。
  • 好吧,我刚刚检查了ServerFaultSuperUserStackOverflow,后者是唯一一个返回接近我的问题的问题和答案的人。所以,虽然我知道,从理论上讲,他们会更适合我的问题,但实践表明 StackOverflow 是最好的地方。

标签: emacs


【解决方案1】:

我终于找到了问题的原因。事实证明,这与我的个人情况相当具体,但我在这里发布答案而不是删除问题,因为:

  1. 事实证明,我的问题确实不同于 StackOverflow 上发出的所有其他类似问题,并在我的帖子中列出。
  2. 我设法诊断问题的方式对其他人可能有用(它确实是作为解决方案的一部分提出的,也是对上述两个问题的评论)。
  3. 尽管它相当具体,但我不是第一个遇到它的人,因为我终于found someone with the same issue(尽管他们没有通过相同的症状识别它)并且我成功地应用了他们的修复。

感谢strace,我真的明白了发生了什么。在 emacs 加载缓慢时获得的跟踪与快速加载时获得的跟踪非常相似,只是在此调用时

faccessat2(AT_FDCWD, "/run/netsop/u/_MTN/format", F_OK, AT_EACCESS) = -1 ENOENT (No such file or directory)

慢速运行在继续之前等待 8 秒,而快速运行则立即继续。

/run/netsop/u/ 是一个网络挂载点,其子文件夹会根据需要自动挂载(并在一段时间后自动卸载),所以发生的事情变得很清楚:emacs 试图查看文件 /run/netsop/u/_MTN/format是否存在,只是为了得到这个答案,它触发了文件夹的安装(这恰好需要或多或少 8 秒)。当挂载点还在运行时再次启动 emacs 时,它会立即得到响应。

一旦知道问题的原因是emacs试图查看_MTN/format是否存在,我google了一下,找到了上面提到的修复方法,就是添加

(setq vc-handled-backends nil)

.emacs,为了禁用emacs的版本控制能力。

当然,更好的解决方法是保留 vc-handled-backends,eg 向 emacs 指定它应该查找的文件夹列表版本控制配置文件,但我不知道这样的解决方案。

【讨论】:

    【解决方案2】:

    是这个吗?

    *** GNU/Linux: slow startup on Linux-based GNU systems.
    
    People using systems based on the Linux kernel sometimes report that
    startup takes 10 to 15 seconds longer than 'usual'.
    
    This is because Emacs looks up the host name when it starts.
    Normally, this takes negligible time; the extra delay is due to
    improper system configuration.  This problem can occur for both
    networked and non-networked machines.
    
    Here is how to fix the configuration.  It requires being root.
    
    **** Networked Case.
    
    First, make sure the files '/etc/hosts' and '/etc/host.conf' both
    exist.  The first line in the '/etc/hosts' file should look like this
    (replace HOSTNAME with your host name):
    
        127.0.0.1      HOSTNAME
    
    Also make sure that the '/etc/host.conf' files contains the following
    lines:
    
        order hosts, bind
        multi on
    
    Any changes, permanent and temporary, to the host name should be
    indicated in the '/etc/hosts' file, since it acts a limited local
    database of addresses and names (e.g., some SLIP connections
    dynamically allocate ip addresses).
    
    **** Non-Networked Case.
    
    The solution described in the networked case applies here as well.
    However, if you never intend to network your machine, you can use a
    simpler solution: create an empty '/etc/host.conf' file.  The command
    'touch /etc/host.conf' suffices to create the file.  The '/etc/hosts'
    file is not necessary with this approach.
    

    引自问题文件;键入 C-hC-p

    【讨论】:

    • 我的 /etc/hosts/etc/host.conf 文件与此处显示的不完全相同,但对我来说似乎是正确的。此外,我了解到他的主机名问题自 emacs 25 以来已得到修复。最后,这似乎与退出后立即重新运行 emacs 会导致快速加载的事实不符。由于我在专业网络上,我宁愿不碰我的/etc/hosts/etc/host.conf 文件。如果你有办法在不触及我的主机配置的情况下确认这个假设(例如,通过查看 strace 的结果中的某些内容,请参阅我的编辑),不过我很乐意检查它。
    • 我无法再添加任何内容,而且我没有确定这是您的问题。这似乎值得检查,作为“慢启动炎”的记录原因。
    猜你喜欢
    • 2013-05-28
    • 1970-01-01
    • 2019-10-02
    • 2010-10-30
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多