草庐IT

windows - git stash 在 Windows 上运行缓慢

coder 2023-06-23 原文

在我的 Windows 机器上,git stash 每次调用都有大约 3.5 秒的开销,这使我的 git 提交 Hook 增加了大约 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 for Windows 2.19 (2018 年 9 月),git stash(和 git rebase)不再是纯脚本,而是使用 git.exe 编译的二进制文件.
参见 git-for-windows/build-extra PR 203 .

要激活它们,输入:

git config --global rebase.useBuiltin true
git config --global stash.useBuiltin true

警告:

As nice as the speed-ups are, the patches in question are still in flux, and they are not battle-tested at all.

所以,目前 git stash 的脚本版本仍然是默认的,这样:

  • users who want the raw speed improvement we got through three Google Summer of Code projects working in parallel can have that,
  • while others who are reluctant to play guinea pig by running only well-tested code can stay on the safe side.

重点仍然是:在下一个版本的 Git 中,git-stash 的 bash 脚本最终会消失,并且它的替代品会更快。

注意:下一个版本将是 Git 2.27(2020 年第 2 季度):“git stash”保留了一个逃生 channel ,以便在几个版本中使用脚本版本,但它已经过时了。

它已被删除。

参见 commit 8a2cd3f , commit b0c7362 (2020 年 3 月 3 日)作者:Thomas Gummerer (tgummerer) .
(由 Junio C Hamano -- gitster -- merge 于 commit 369ae75,2020 年 3 月 27 日)

stash: remove the stash.useBuiltin setting

Signed-off-by: Thomas Gummerer

Remove the stash.useBuiltin setting which was added as an escape hatch to disable the builtin version of stash first released with Git 2.22.

Carrying the legacy version is a maintenance burden, and has in fact become out of date failing a test since the 2.23 release, without anyone noticing until now.

So users would be getting a hint to fall back to a potentially buggy version of the tool.

We used to shell out to git config to get the useBuiltin configuration to avoid changing any global state before spawning legacy-stash.
However that is no longer necessary, so just use the 'git_config' function to get the setting instead.

Similar to what we've done in d03ebd411c ("rebase: remove the rebase.useBuiltin setting", 2019-03-18, Git v2.22.0-rc0 -- merge listed in batch #5), where we remove the corresponding setting for rebase, we leave the documentation in place, so people can refer back to it when searching for it online, and so we can refer to it in the commit message.


2019 年第二季度更新,使用 Git 2.22,git stash 完全用 C 重写。 ² 参见 commit 40af146 , commit 48ee24a , commit ef0f0b4 , commit 64fe9c2 , commit 1ac528c , commit d553f53 , commit d4788af , commit 41e0dd5 , commit dc7bd38 , commit 130f269 , commit bef55dc , commit dac566c , commit ab8ad46 (2019 年 2 月 25 日)Paul-Sebastian Ungureanu (weekly-digest[bot]) .
参见 commit c4de61d , commit 577c199 , commit 4e2dd39 , commit 8a0fc8d (2019 年 2 月 25 日)Joel Teichroeb (klusark) .
参见 commit 7906af0 , commit 90a4627 , commit 8d8e9c2 (2019 年 2 月 25 日)Johannes Schindelin (dscho) .
(由 Junio C Hamano -- gitster -- merge 于 commit e36adf7 ,2019 年 4 月 22 日)

您仍然可以 use the shell script with git legacy-stash .

和:

stash: convert stash--helper.c into stash.c

The old shell script git-stash.sh was removed and replaced entirely by builtin/stash.c.
In order to do that, create and push were adapted to work without stash.sh.

For example, before this commit, git stash create called git stash--helper create --message "$*". If it called git stash--helper create "$@", then some of these changes wouldn't have been necessary.

This commit also removes the word helper since now stash is called directly and not by a shell script.

有优化:

stash: optimize get_untracked_files() and check_changes()

This commits introduces a optimization by avoiding calling the same functions again.
For example, git stash push -u would call at some points the following functions:

  • check_changes() (inside do_push_stash())
  • do_create_stash(), which calls: check_changes() and get_untracked_files()

Note that check_changes() also calls get_untracked_files().
So, check_changes() is called 2 times and get_untracked_files() 3 times.

The old function check_changes() now consists of two functions: get_untracked_files() and check_changes_tracked_files().

These are the call chains for push and create:

  • push_stash() -> do_push_stash() -> do_create_stash()
  • create_stash() -> do_create_stash()

To prevent calling the same functions over and over again, check_changes() inside do_create_stash() is now placed in the caller functions (create_stash() and do_push_stash()).
This way check_changes() and get_untracked files() are called only one time.


在 Git 2.36(2022 年第 2 季度)中,警告“the stash.useBuiltin support has been removed!”的删除终于完成了!

参见 commit e9b272e , commit deeaf5e , commit 5d4dc38 , commit 6de0722 (2022 年 1 月 27 日)Johannes Schindelin (dscho) .
(由 Junio C Hamano -- gitster -- merge 于 commit b9f791a ,2022 年 2 月 16 日)

stash: stop warning about the obsolete stash.useBuiltin config setting

Signed-off-by: Johannes Schindelin

In 8a2cd3f ("stash: remove the stash.useBuiltin setting", 2020-03-03, Git v2.27.0-rc0 -- merge listed in batch #2), we removed support for stash.useBuiltin, but left a warning in its place.

After almost two years, and several major versions, it is time to remove even that warning.

关于windows - git stash 在 Windows 上运行缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37529016/

有关windows - git stash 在 Windows 上运行缓慢的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  3. ruby - 如何每月在 Heroku 运行一次 Scheduler 插件? - 2

    在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/

  4. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  5. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  6. ruby - Sinatra:运行 rspec 测试时记录噪音 - 2

    Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/

  7. ruby-on-rails - 无法让 rspec、spork 和调试器正常运行 - 2

    GivenIamadumbprogrammerandIamusingrspecandIamusingsporkandIwanttodebug...mmm...let'ssaaay,aspecforPhone.那么,我应该把“require'ruby-debug'”行放在哪里,以便在phone_spec.rb的特定点停止处理?(我所要求的只是一个大而粗的箭头,即使是一个有挑战性的程序员也能看到:-3)我已经尝试了很多位置,除非我没有正确测试它们,否则会发生一些奇怪的事情:在spec_helper.rb中的以下位置:require'rubygems'require'spork'

  8. ruby - 在 Windows 机器上使用 Ruby 进行开发是否会适得其反? - 2

    这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby​​-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub

  9. ruby-on-rails - before_filter 运行多个方法 - 2

    是否有可能:before_filter:authenticate_user!||:authenticate_admin! 最佳答案 before_filter:do_authenticationdefdo_authenticationauthenticate_user!||authenticate_admin!end 关于ruby-on-rails-before_filter运行多个方法,我们在StackOverflow上找到一个类似的问题: https://

  10. Vscode+Cmake配置并运行opencv环境(Windows和Ubuntu大同小异) - 2

    之前在培训新生的时候,windows环境下配置opencv环境一直教的都是网上主流的vsstudio配置属性表,但是这个似乎对新生来说难度略高(虽然个人觉得完全是他们自己的问题),加之暑假之后对cmake实在是爱不释手,且这样配置确实十分简单(其实都不需要配置),故斗胆妄言vscode下配置CV之法。其实极为简单,图比较多所以很长。如果你看此文还配不好,你应该思考一下是不是自己的问题。闲话少说,直接开始。0.CMkae简介有的人到大二了都不知道cmake是什么,我不说是谁。CMake是一个开源免费并且跨平台的构建工具,可以用简单的语句来描述所有平台的编译过程。它能够根据当前所在平台输出对应的m

随机推荐