Visual Studio 2017中的Git非常缓慢。

3
我进行了基本的检查,如不在网络驱动器上放置文件夹、更改特定的git配置设置、使用不同的存储库、进行反病毒扫描等。

到目前为止,我知道问题与我的Windows帐户无关。在另一台设备上,切换分支只需要几秒钟,而不是一分钟。我们注意到在 电脑上有更多的网络流量。

当我以安全模式运行Visual Studio时,

devenv.exe /SafeMode

我立刻在“团队资源管理器”中看到以下错误:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(Int32 hr, Int32[] expectedHRFailure)
   at Microsoft.TeamFoundation.Git.Provider.ServiceProviderExtensionMethods.EnsurePackageLoaded(IServiceProvider serviceProvider, Guid packageGuid)
   at Microsoft.TeamFoundation.Git.Provider.ServiceProviderExtensionMethods.EnsureSccAndTfPackagesLoaded(IServiceProvider serviceProvider)
   at Microsoft.TeamFoundation.Git.Provider.Repositories.GitTeamProjectExtendedInfoProvider.set_ServiceProvider(IServiceProvider value)
   at Microsoft.VisualStudio.TeamFoundation.TeamExplorer.ConnectPage.ConnectPageVS.Initialize(Object sender, PageInitializeEventArgs e)
   at Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.Framework.TeamExplorerPageHost.Initialize(TeamExplorerPageContext context)

建议如msdn所示,我尝试的第一件事是:
devenv.exe /updateConfiguration

但这并没有解决问题。然后我运行了:
devenv.exe /setup

它会显示以下错误信息:

无法完成操作。所请求的操作需要提升权限。

devenv.exe /SafeMode /log D:\temp

我在日志中看到的错误是:
Error loading UI library for package WebEditorPackage. HrLoadNativeUILibrary failed with 0x800a006f.
Error loading UI library for package Microsoft.VsSDK.ExtensibilityProjectFlavor.ExtensibilityProjectFlavorPackage. HrLoadNativeUILibrary failed with 0x800a006f.
Failed to find CTMENU resource '#1000' in loaded UI library.

我以管理员身份运行了Visual Studio。问题仍然存在,但是当之后作为用户在安全模式下运行时,日志中不再有任何错误行。

常规启动时,我看到一个错误和许多警告:

ERROR Encountered an ArgumentException when trying to look up the key binding information for ({ef254ccf-cee3-43e9-a22c-3ae3ab08e7fe},256) in the scope {5efc7975-14bc-11cf-9b2b-00aa00573819}.
Unexpected system error mode before loading package [Microsoft.VisualStudio.Services.Promotions.PromotionsPackage]
Unexpected system error mode before loading package [InstallerPackage]
About to block on async service creation because the service was requested via GetService. This has the potential to deadlock. Async initializing services should be retrieved via GetServiceAsync.

PkgDef syntax or I/O error at line 1: Section header: additional characters after closing bracket
      [$RootKey$\Setup\[ProductName]]  80004005 - E_FAIL
PkgDef syntax or I/O error at line 3: Section header: additional characters after closing bracket
      "SrcPath"="[SourceDir]"  80004005 - E_FAIL
Could not process PkgDef file
      C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\Community\Detection_Keys_Reg.pkgdef 

一个Visual Studio的修复也没有解决问题。我正在使用Visual Studio 15.6.5。
我运行了sfc来检查Windows系统文件。
sfc /scannow

Beginning system scan.  This process will take some time.

Beginning verification phase of system scan.
Verification 100% complete.

Windows Resource Protection found corrupt files but was unable to fix some
of them. Details are included in the CBS.Log windir\Logs\CBS\CBS.log. For
example C:\Windows\Logs\CBS\CBS.log. Note that logging is currently not
supported in offline servicing scenarios.

这样的错误有很多:
CSI    000010f2 [DIRSD OWNER WARNING] Directory [l:48 ml:49]'\??\C:\Program Files\Windows Identity Foundation' is not owned but specifies SDDL in component c2wtsres, arch amd64, nonSxS, pkt {l:8 b:31bf3856ad364e35}
CSI    000010f3 [DIRSD OWNER WARNING] Directory [l:53 ml:54]'\??\C:\Program Files\Windows Identity Foundation\v3.5' is not owned but specifies SDDL in component c2wtsres, arch amd64, nonSxS, pkt {l:8 b:31bf3856ad364e35}
CSI    000010f4 Error - Overlap: Duplicate ownership for directory \??\C:\Program Files\Windows Identity Foundation in component c2wtsres, version 10.0.14393.0, arch amd64, nonSxS, pkt {l:8 b:31bf3856ad364e35}
CSI    000010f5 Error - Overlap: Duplicate ownership for directory \??\C:\Program Files\Windows Identity Foundation\v3.5 in component c2wtsres, version 10.0.14393.0, arch amd64, nonSxS, pkt {l:8 b:31bf3856ad364e35}

Process Monitor日志显示在Git和VS之间切换。磁盘操作本身很快,但是在git.exe FileCloses C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\bin\git.exe后,它需要几乎一秒钟才能关闭C:\Windows。并且在来自git.exe的QueryNameInformationFile事件之后,它会在C:\Windows\System32\conhost.exe上执行CloseFile操作,大约一秒钟后。

当没有特殊情况发生时,我进行了Wireshark捕获。我看到我的PC和webdefence.cluster-x.websense.net之间有大量流量,这是公司代理服务器。流量比我的同事多得多,他们没有看到错误。

Wireshark log webdefence.cluster-x.websense.net

使用有线、无线或VPN连接在家中时,问题仍然存在。
我怀疑这是NTFS权限的问题?
我尝试运行SFCFix,但没有成功。
SFCFix Has Crashed


Something has gone horribly wrong and SFCFix has crashed. Would you like SFCFix
to submit a crash report to the developer so that this problem can be fixed?
Type "y" for yes or "n" for no and press enter to continue:

我还尝试了其他工具,但都没有成功。
D:\Tools>DISM /Online /Cleanup-Image /StartComponentCleanup /ResetBase

Deployment Image Servicing and Management tool
Version: 10.0.14393.0

Image Version: 10.0.14393.0

[===========                20.0%                          ]
The operation completed successfully.

D:\Tools>Dism /Online /Cleanup-Image /RestoreHealth

Deployment Image Servicing and Management tool
Version: 10.0.14393.0

Image Version: 10.0.14393.0

[==========================100.0%==========================]
Error: 0x800f081f

The source files could not be found.
Use the "Source" option to specify the location of the files that are required to restore the feature. For more information on specifying a source location, see http://go.microsoft.com/fwlink/?LinkId=243077.

The DISM log file can be found at C:\WINDOWS\Logs\DISM\dism.log

Tweaking.com - Windows Repair 2018也无法修复文件权限。

(1)使用独立的Git切换分支也很慢吗? (2)在长时间切换分支期间,进程树是什么样子的?有哪些进程(如果有的话)会消耗CPU? - undefined
好问题。我已经安装了TortoiseGit,但还没有测试过。在这方面没有问题:切换分支不到4秒钟,没有出现任何消耗CPU的情况。 - undefined
有些进程完成需要很长时间。可能是因为它在等待某些网络调用。请找出并分享相关的进程树部分。 - undefined
TortoiseGit在这里并不是最佳选择,因为它使用了另一种实现方式。Windows平台上的标准git命令行界面会更好一些。 - undefined
Git for Windows CMD也可以正常工作。 - undefined
我更新了问题,提供了更多有关磁盘访问和网络流量的信息。我怀疑这是一个NTFS问题。 - undefined
2个回答

4
在该目录中删除“Git”文件夹并重新启动VS:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer

该文件夹会覆盖您正常的Git执行。 附注:如果您没有使用“Community”版本,请进行相应修改。

1
似乎删除这个文件夹只是强制VS使用系统上默认安装的git。所以在我的情况下,起初它确实有帮助,直到我更新到git版本2.23之后,一切又开始变得缓慢。回退到版本2.22完全解决了这个问题。 - undefined
谢谢。也适用于VS 2022。 - undefined

0

这可能是一个硬件问题,涉及到 Lenovo L460 - e-ID 读卡器 i7 固态硬盘

系统已重新安装。SFC 发现了一些错误并修复了它们。Wireshark 中的流量看起来正常,但问题仍然存在。第一次登录系统的同事也遇到了相同的问题。

我唯一注意到的另一件事是当 Opera 浏览器启动时,在第一分钟内无法显示新的网页。网站加载时间很长。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接