2016-05-30 65 views
29

在我的windows机器上git stash每次调用的开销大约为3.5秒,这为我的git commit钩子增加了大约7秒。git暗藏在窗口上很慢

在linux(同一台机器)下的相同命令大约需要0.01秒。性能问题也适用于空存储库。

我试图从this threadthis thread如下:

  • core.fscache设置为true
  • core.preloadindex设置为true
  • gc.auto设置为256
  • 设置PS1 = '$'
  • 在管理中运行cmd N模式
  • CMD.EXE而不是混帐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命令之间运行3秒,并运行git-rev-parse。有没有其他的标志可以用来找到瓶颈?

+0

这可能是你的仓库很大,你可以尝试在你的本地和远程仓库上启动'git gc'吗? – Flows

+0

它在一个空的存储库中花费相同的时间量。我已经更新了这个问题。 – sighol

+0

@sighol你经历了[这个线程](http://stackoverflow.com/questions/4485059/git-bash-is-extremely-slow-in-windows-7-x64)和测试[这个提示](http ://stackoverflow.com/a/2967519/365237) – eis

回答

3

git-stash是一个脚本,而不是编译在git.exe二进制文件中的命令。

在Linux上:我能找到git-stash/usr/lib/git-core/git-stash - 我会让你看起来对于Windows上的正确路径...


此脚本使用#!/bin/sh跑,我不知道什么shell执行在Windows上运行时使用。

你可以尝试其他兼容壳(这里的bash):运行

# the git-core/ dir needs to be in the PATH, 
# obviously you will need to provide the correct path for your git-core dir 

$ PATH=/usr/lib/git-core:$PATH bash /usr/lib/git-core/git-stash 

你也可以把-x标志,将打印执行的所有命令的痕迹,如果一个目视检查的子命令似乎是衣架:

$ PATH=/usr/lib/git-core:$PATH bash -x /usr/lib/git-core/git-stash