的速度——如何解决这个问题

的速度——如何解决这个问题

本文介绍了Git 减慢了 Emacs 的速度——如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开文件(通过输入Ctrl-x f,AKA Find File)或在文件上输入f>Dired 模式),在具有 .git 子目录的工作目录中非常缓慢.

Opening a file (either by typing Ctrl-x f, AKA Find File) or by typing f on that file in Dired mode), is painfully slow in working directories that have a .git subdirectory.

即使是最简单的文件(50 行,大部分是注释)也可能需要 8 秒才能打开.

Even the simplest file (50 lines with mostly comments) could take up to 8 seconds to open.

在不由 Git 管理的不同目录中的同一个文件会立即打开.

The same file, in a different directory not managed by Git, opens in a jiffy, immediately.

为什么会发生这种情况,如何在不禁用 vc 模式的情况下解决此问题??(因为我使用 Emacs 的主要原因之一是它的 M-x ediff-revision)

Why is this happening and how can I fix this without disabling vc-mode? (since one of the main reasons I use Emacs is its M-x ediff-revision)

更新 1:感谢@sanityinc 在下面的回答,我运行了 ELP Profiling,这是我收到的(对于一个非常小的文件,69 行,其中 59 行是简单的评论):>

UPDATE 1: Thanks to @sanityinc's answer below, I ran ELP Profiling and this is what I received (for a very small file, 69 lines, 59 of which are plain comments):

Function Name                       Call Count   Elapsed Time  Average Time
-------------                       ----------   ------------  ------------
vc-call-backend                      11          23.023        2.093
vc-find-file-hook                    1           8.757         8.757
vc-mode-line                         1           7.812         7.812
vc-default-mode-line-string          1           7.345         7.345
vc-state-refresh                     1           6.921         6.921
vc-state                             1           6.921         6.921
vc-default-state-heuristic           1           6.921         6.921
vc-registered                        1           0.945         0.945
vc-backend                           1           0.945         0.945
vc-git-registered                    1           0.912         0.912
vc-working-revision                  1           0.4240000000  0.4240000000
vc-find-root                         4           0.0990000000  0.0247500000
vconcat                              623         0.0220000000  3.53...e-005
vc-bzr-registered                    1           0.016         0.016
vc-check-master-templates            2           0.014         0.007
vc-default-registered                2           0.014         0.007
vc-rcs-registered                    1           0.008         0.008
vc-sccs-registered                   1           0.006         0.006
vc-svn-registered                    1           0.002         0.002
vc-cvs-registered                    1           0.001         0.001
vc-sccs-search-project-dir           1           0.0           0.0
vc-kill-buffer-hook                  6           0.0           0.0
vc-find-backend-function             11          0.0           0.0
vc-default-find-file-hook            1           0.0           0.0
vc-possible-master                   6           0.0           0.0
vc-file-clearprops                   1           0.0           0.0
vc-file-setprop                      3           0.0           0.0
vc-file-getprop                      5           0.0           0.0
vc-make-backend-sym                  15          0.0           0.0

这是很好的信息,但我不是 Emacs/elisp 专家,那么我该怎么做呢?

This is great information but I am not an Emacs/elisp expert, so how where do I go from here?

更新 2: 在将这个问题搁置一段时间后,我发现了这篇很棒的博文:Cygwin 缓慢启动:发现了罪魁祸首! 这实质上表明在后台启动 bash 完成.我很快实现了它并重新运行了 ELP 分析测试:

UPDATE 2: After putting this problem on the back burner for a while, I came across this great blog post: Cygwin slow start up: the culprit discovered! which essentially suggests starting bash completion in the background. I quickly implemented it and re-ran the ELP profiling test:

vc-call-backend                      11          14.489        1.317
vc-find-file-hook                    1           5.488         5.488
vc-mode-line                         1           5.118         5.118
vc-default-mode-line-string          1           4.719         4.719
vc-state-refresh                     1           4.282         4.282
vc-state                             1           4.282         4.282
vc-default-state-heuristic           1           4.282         4.282
vc-working-revision                  1           0.437         0.437
vc-registered                        1           0.37          0.37
vc-backend                           1           0.37          0.37
vc-git-registered                    1           0.34          0.34
vc-find-root                         4           0.088         0.022
vc-bzr-registered                    1           0.015         0.015
vc-check-master-templates            2           0.013         0.0065
vc-default-registered                2           0.013         0.0065
vc-rcs-registered                    1           0.007         0.007
vc-sccs-registered                   1           0.006         0.006
vc-cvs-registered                    1           0.001         0.001
vconcat                              623         0.001         1.60...e-006
vc-svn-registered                    1           0.001         0.001
vc-sccs-search-project-dir           1           0.0           0.0
vc-kill-buffer-hook                  6           0.0           0.0
vc-find-backend-function             11          0.0           0.0
vc-default-find-file-hook            1           0.0           0.0
vc-possible-master                   6           0.0           0.0
vc-file-clearprops                   1           0.0           0.0
vc-file-setprop                      3           0.0           0.0
vc-file-getprop                      5           0.0           0.0
vc-make-backend-sym                  15          0.0           0.0

很高兴看到 vc-call-backend 从 23 秒下降到 14 秒,但这仍然是不可接受的(找到一个 CVS 控制的文件只需要不到一秒钟的时间!).

It's great to see vc-call-backend going down from 23 seconds to 14 seconds, but this is still unacceptable (finding a CVS-controlled file takes less than a split-second!).

更新 3: 无法解开谜团,我通过升级到最新的 cygwin (1.7.9-1) 来试试运气.那没有帮助.

UPDATE 3: Unable to solve the mystery, I tried my luck by upgrading to the latest cygwin (1.7.9-1). That didn't help.

所以,我决定尝试将沙箱(连同它的 .git 子目录)从 Samba 共享移动到本地存储(C:UsersWinWinDocuments).然后我重新运行了 ELP 分析测试:

So, I decided to try moving the sandbox (along with its .git subdirectory) from the Samba share to local storage (C:UsersWinWinDocuments). I then re-ran the ELP profiling test:

vc-call-backend                           11          2.082         0.1892727272
vc-find-file-hook                         1           0.897         0.897
vc-git--call                              7           0.8929999999  0.1275714285
vc-git-mode-line-string                   1           0.78          0.78
vc-mode-line                              1           0.78          0.78
vc-default-mode-line-string               1           0.655         0.655
vc-git--out-ok                            5           0.6519999999  0.1304
vc-git-state                              1           0.53          0.53
vc-state-refresh                          1           0.53          0.53
vc-state                                  1           0.53          0.53
vc-default-state-heuristic                1           0.53          0.53
vc-git-working-revision                   2           0.25          0.125
vc-git-registered                         2           0.2239999999  0.1119999999
vc-git--run-command-string                1           0.18          0.18
vc-working-revision                       1           0.125         0.125
vc-registered                             1           0.1169999999  0.1169999999
vc-backend                                2           0.1169999999  0.0584999999
vc-git--empty-db-p                        1           0.11          0.11
vc-find-root                              3           0.003         0.001
vc-git-root                               2           0.002         0.001
vc-check-master-templates                 2           0.001         0.0005
vc-sccs-registered                        1           0.001         0.001
vc-default-registered                     2           0.001         0.0005
vc-bzr-registered                         1           0.001         0.001
vc-rcs-registered                         1           0.0           0.0
vc-sccs-search-project-dir                1           0.0           0.0
vc-kill-buffer-hook                       5           0.0           0.0
vc-default-find-file-hook                 1           0.0           0.0
vc-possible-master                        6           0.0           0.0
vc-cvs-registered                         1           0.0           0.0
vc-file-clearprops                        1           0.0           0.0
vc-file-setprop                           3           0.0           0.0
vc-file-getprop                           5           0.0           0.0
vc-svn-registered                         1           0.0           0.0
vc-make-backend-sym                       2           0.0           0.0

哇!这将 vc-call-backend 从 14 秒降低到 2 秒.这很棒但并不美妙,因为使用 Emacs/CVS 我能够在 不到 35 毫秒 内访问一个文件——在沙箱最初所在的同一个 Samba 共享上:

Wow! That lowered vc-call-backend from 14 seconds to 2 seconds. This is great but not wonderful, because with Emacs/CVS I am able to visit a file in less than 35ms -- on the same Samba share where the sandbox originally resides:

vc-call-backend                           5           0.031         0.0062
vc-find-file-hook                         1           0.031         0.031
vc-registered                             1           0.031         0.031
vc-backend                                1           0.031         0.031
vc-rcs-registered                         1           0.016         0.016
vc-check-master-templates                 1           0.016         0.016
vc-default-registered                     1           0.016         0.016
vc-insert-file                            1           0.015         0.015
vc-cvs-get-entries                        1           0.015         0.015
vc-cvs-registered                         1           0.015         0.015
vc-cvs-state-heuristic                    1           0.0           0.0
vc-cvs-parse-sticky-tag                   1           0.0           0.0
vc-kill-buffer-hook                       1           0.0           0.0
vc-find-backend-function                  1           0.0           0.0
vc-cvs-parse-entry                        1           0.0           0.0
vc-mode-line                              1           0.0           0.0
vc-default-find-file-hook                 1           0.0           0.0
vc-possible-master                        3           0.0           0.0
vc-cvs-mode-line-string                   1           0.0           0.0
vc-default-mode-line-string               1           0.0           0.0
vc-state-refresh                          1           0.0           0.0
vc-working-revision                       1           0.0           0.0
vc-state                                  1           0.0           0.0
vc-file-clearprops                        1           0.0           0.0
vc-file-setprop                           5           0.0           0.0
vc-file-getprop                           7           0.0           0.0
vc-make-backend-sym                       2           0.0           0.0

这提出了两个问题:

  1. git+cygwin 的组合使得它对网速?
  2. 我怎样才能让 git 减少到 50 毫秒以内?毕竟是通话快速版本控制系统"

使用 msysgit 1.7.8 时更新:

vc-call-backend                      11          0.626         0.0569090909
vc-find-file-hook                    1           0.281         0.281
vc-mode-line                         1           0.2189999999  0.2189999999
vc-default-mode-line-string          1           0.1879999999  0.1879999999
vc-state-refresh                     1           0.157         0.157
vc-state                             1           0.157         0.157
vc-default-state-heuristic           1           0.157         0.157
vc-registered                        1           0.062         0.062
vc-backend                           1           0.062         0.062
vc-git-registered                    1           0.062         0.062
vc-working-revision                  1           0.0310000000  0.0310000000
vc-rcs-registered                    1           0.0           0.0
vc-sccs-search-project-dir           1           0.0           0.0
vc-kill-buffer-hook                  6           0.0           0.0
vc-find-backend-function             11          0.0           0.0
vc-default-find-file-hook            1           0.0           0.0
vc-possible-master                   6           0.0           0.0
vc-check-master-templates            2           0.0           0.0
vc-cvs-registered                    1           0.0           0.0
vc-sccs-registered                   1           0.0           0.0
vc-file-clearprops                   1           0.0           0.0
vconcat                              623         0.0           0.0
vc-default-registered                2           0.0           0.0
vc-file-setprop                      3           0.0           0.0
vc-find-root                         4           0.0           0.0
vc-file-getprop                      5           0.0           0.0
vc-bzr-registered                    1           0.0           0.0
vc-svn-registered                    1           0.0           0.0
vc-make-backend-sym                  15          0.0           0.0

你能看出区别吗?:)

现在 Emacs 下的 Git 快得多了,但它仍然比 Emacs 下的 CVS 慢得多.所以我不知道为什么 Git 被称为快速版本控制系统".它可能比 CVS 更好,但更快?

Git under Emacs is way faster now, but it still much much slower than CVS under Emacs. So I have no idea why Git is called the "Fast Version Control System". It may be better than CVS, but faster?

推荐答案

有一个名为 ELP 的内置分析器.你可以试试M-x elp-instrument-package之类的,输入vc",然后尝试找文件.之后,M-x elp-results 将向您显示一份个人资料报告.

There's a built-in profiler called ELP. You can try something like M-x elp-instrument-package, enter "vc", and then try finding a file. Afterwards, M-x elp-results will show you a profile report.

(请注意,如果时间花在与 vc 无关的功能上,则此技术不会显示它,但如果您愿意,可以检测更多包.)

(Note that if the time is instead being spent in non-vc-related functions, this technique will not show it, but you can instrument further packages if you like.)

这篇关于Git 减慢了 Emacs 的速度——如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 17:24