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
当我使用259b5e6d33
进行git difftool
时,结果非常缓慢:
$ 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
的结果,我测量了在 git-difftool
中花费了 2.8 秒,在 git-difftool--helper
中花费了 7.5 秒。后者有 98 行代码。我不明白为什么速度会这么慢。