我注意到这git difftool
很慢。每次差异调用之间会出现大约 1..2 秒的延迟。
为了对其进行基准测试,我编写了一个自定义difftool
命令:
#!/bin/sh
echo $0 $1 $2
并将 Git 配置为在我的~/.gitconfig
[diff]
tool = mydiff
[difftool "mydiff"]
prompt = false
cmd = "~/mydiff \"$LOCAL\" \"$REMOTE\""
我在 Git 源代码上对其进行了测试:
$ git clone https://github.com/git/git.git
$ cd git
$ git rev-parse HEAD
1bc8feaa7cc752fe3b902ccf83ae9332e40921db
$ git diff head~10 --stat --name-only | wc -l
23
当我用 a 计时git difftool
时259b5e6d33
,结果慢得离谱:
$ time git difftool 259b5
mydiff /dev/null Documentation/RelNotes/2.6.3.txt
...
mydiff /tmp/mY2T6l_upload-pack.c upload-pack.c
real 0m10.381s
user 0m1.997s
sys 0m6.667s
通过尝试更简单的脚本,它会更快:
$ time git diff --name-only --stat 259b5 | xargs -n1 -I{} sh -c 'git show 259b5:{} > {}.tmp && ~/mydiff {} {}.tmp'
mydiff Documentation/RelNotes/2.6.3.txt Documentation/RelNotes/2.6.3.txt.tmp
mydiff upload-pack.c upload-pack.c.tmp
real 0m1.149s
user 0m0.472s
sys 0m0.821s
我错过了什么?
这是我得到的结果
| Cygwin | Debian | Ubuntu | Method |
| ------ | ------ | ------ | -------- |
| 10.381 | 2.620 | 0.580 | difftool |
| 1.149 | 0.567 | 0.210 | custom |
对于Cygwin
结果,我测量了 2.8 秒git-difftool
和 7.5 秒的git-difftool--helper
. 后者有 98 行长。我不明白为什么这么慢。