【发布时间】:2016-09-28 11:33:09
【问题描述】:
在我的 Windows 机器上,git stash 每次调用有大约 3.5 秒的开销,这给我的 git commit 钩子增加了大约 7 秒。
linux下(同一台机器)下相同的命令大约需要0.01秒。性能问题也适用于空存储库。
我从this thread 和this thread 尝试了以下方法:
-
core.fscache设置为true -
core.preloadindex设置为true -
gc.auto设置为256 - 设置 PS1='$'
- 在管理模式下运行 cmd
- 在 cmd.exe 中运行而不是 git-bash
运行GIT_TRACE=true git stash list
16:58:16.844591 git.c:563 trace: exec: 'git-stash' 'list'
16:58:16.844591 run-command.c:336 trace: run_command: 'git-stash' 'list'
16:58:19.699591 git.c:350 trace: built-in: git 'rev-parse' '--git-dir'
16:58:19.859591 git.c:350 trace: built-in: git 'rev-parse' '--git-path' 'objects'
16:58:20.069591 git.c:350 trace: built-in: git 'rev-parse' '--show-toplevel'
16:58:20.154591 git.c:350 trace: built-in: git 'rev-parse' '--git-path' 'index'
16:58:20.244591 git.c:350 trace: built-in: git 'config' '--get-colorbool' 'color.interactive'
16:58:20.334591 git.c:350 trace: built-in: git 'config' '--get-color' 'color.interactive.help' 'red bold'
16:58:20.424591 git.c:350 trace: built-in: git 'config' '--get-color' '' 'reset'
16:58:20.514591 git.c:350 trace: built-in: git 'rev-parse' '--verify' '--quiet' 'refs/stash'
real 0m3.845s
user 0m0.000s
sys 0m0.047s
运行GIT_TRACE_PERFORMANCE=true git stash list
16:59:18.414591 trace.c:420 performance: 0.001078046 s: git command: 'C:\Program Files\Git\mingw64\libexec\git-core\git.exe' 'rev-parse' '--git-dir'
16:59:18.569591 trace.c:420 performance: 0.000947184 s: git command: 'C:\Program Files\Git\mingw64\libexec\git-core\git.exe' 'rev-parse' '--git-path' 'objects'
16:59:18.779591 trace.c:420 performance: 0.001253627 s: git command: 'C:\Program Files\Git\mingw64\libexec\git-core\git.exe' 'rev-parse' '--show-toplevel'
16:59:18.869591 trace.c:420 performance: 0.001285517 s: git command: 'C:\Program Files\Git\mingw64\libexec\git-core\git.exe' 'rev-parse' '--git-path' 'index'
16:59:18.955591 trace.c:420 performance: 0.001139994 s: git command: 'C:\Program Files\Git\mingw64\libexec\git-core\git.exe' 'config' '--get-colorbool' 'color.interactive'
16:59:19.040591 trace.c:420 performance: 0.001182881 s: git command: 'C:\Program Files\Git\mingw64\libexec\git-core\git.exe' 'config' '--get-color' 'color.interactive.help' 'red bold'
16:59:19.125591 trace.c:420 performance: 0.001128997 s: git command: 'C:\Program Files\Git\mingw64\libexec\git-core\git.exe' 'config' '--get-color' '' 'reset'
16:59:19.215591 trace.c:420 performance: 0.001567766 s: git command: 'C:\Program Files\Git\mingw64\libexec\git-core\git.exe' 'rev-parse' '--verify' '--quiet' 'refs/stash'
16:59:19.295591 trace.c:420 performance: 3.730583540 s: git command: 'C:\Program Files\Git\mingw64\bin\git.exe' 'stash' 'list'
real 0m3.819s
user 0m0.000s
sys 0m0.062s
从日志中我们看到,从运行 git-stash 命令到运行 git-rev-parse 大约需要 3 秒。我可以运行其他任何标志来查找瓶颈吗?
【问题讨论】:
-
您的存储库可能很大,您可以尝试在本地和远程存储库上启动
git gc吗? -
在空存储库中花费相同的时间。我已经更新了问题。
-
本地 git repo 是托管在本地驱动器上还是远程/网络上?
-
如果你只是想让事情更快地工作,你可以尝试创建一个临时分支,在那里提交所有内容,你将获得与隐藏更改相同的效果(我经常这样做)。但是,如果您提出这个问题是为了更好地了解 stash 功能的工作原理,那么您可以查看 git 源代码:github.com/git/git
标签: windows git git-bash git-stash