git藏匿在窗户上很慢 [英] git stash is slow on windows

查看:276
本文介绍了git藏匿在窗户上很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows机器上,每个调用都有大约3.5秒的时间开销,这为我的git commit钩子增加了大约7秒。


git stash

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



我从此主题 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:内置:git'rev-parse''--verify''--quiet''refs / stash'

real 0m3.845s
用户0m0.000s
sys 0m0.047s

运行 GIT_TRACE_PERFORMANCE = true git stash list $ b $ p $ 16:59:18.414591 trace.c:420性能:0.001078046 s:git命令:'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性能:0.001253627 s:git命令:'C:\ Program Files \Git\mingw64\libexec\git-core\git.exe''rev -parse''--show-toplevel'
16:59:18.869591 trace.c:420性能:0.001285517 s:git命令:'C:\Program Fil es\Git\mingw64\libexec\git-core\git.exe''rev-parse''--git-path''index'
16:59:18.955591 trace.c:420性能:0.001139994 s:git命令:'C:\ Program Files \Git\mingw64\libexec\git-core\git.exe''config''--get-colorbool''color.interactive'
16:59:19.040591 trace.c:420性能:0.001182881 s:git命令:'C:\ Program Files \Git\mingw64\libexec\git-core\git.exe'' config''--get-color''color.interactive.help''红色粗体'
16:59:19.125591 trace.c:420性能:0.001128997 s:git命令:'C:\程序文件\\ git\mingw64\libexec\git-core\git.exe''config''--get-color''''reset'
16:59:19.215591 trace.c:420性能: 0.001567766 s:git命令:'C:\ Program Files \Git\mingw64\libexec\git-core\git.exe''rev-parse''--verify''--quiet''refs / stash'
16:59:19.295591 trace.c:420性能:3.730583540 s:git命令:'C:\ Program Files \Git\mingw64\bin\git.exe''stash''list'

real 0m3.819s
用户0m0.000s
sys 0m0.062s

从日志中我们可以看到,git-stash命令运行和运行git-rev-parse。是否还有其他标志可以运行以找到瓶颈?

解决方案

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



在linux上:我可以在 / usr / lib / git-core / git-stash 找到 git-stash - 我会让你在窗口中寻找正确的路径...


$ b

这个脚本使用#!/ bin / sh 来运行,我不知道在Windows上运行时使用了哪个shell实现。



你可以尝试运行它另一个兼容的shell(这里是:bash):

pre $ #git-core / dir需要在PATH中,
#显然你需要为你的git-core目录提供正确的路径

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

您也可以将 -x 标志,它将打印所有执行的命令的跟踪信息,并通过目测检查是否打开e的子命令似乎是挂钩:

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


On my windows machine git stash has about 3.5 seconds overhead on each invocation, which adds about 7 seconds to my git commit hook.

The same command under linux (same machine) takes about 0.01 seconds. The performance issue applies to empty repositories as well.

I have tried the following from this thread and this thread:

  • core.fscache is set to true
  • core.preloadindex is set to true
  • gc.auto is set to 256
  • Setting PS1='$ '
  • Running cmd in administration mode
  • Running inside cmd.exe instead of git-bash

Running 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

Running 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                                                                                                                                                                                          

From the log we see that it takes around 3 seconds between the git-stash command is run and the git-rev-parse is run. Are there any other flags I can run to find the bottleneck?

解决方案

git-stash is a script, not a command compiled in the git.exe binary.

On linux : I can find git-stash at /usr/lib/git-core/git-stash - I will let you look for the correct path on windows ...


This script uses #!/bin/sh to run, I don't know what shell implementation is used when you run this on windows.

You can try to run it with another compatible shell (here: 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

You can also turn the -x flag, which will print a trace of all commands executed, and visually check if one of the sub commands seems to be the hanger :

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

这篇关于git藏匿在窗户上很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆