microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.71k stars 29.45k forks source link

Git status is triggering far too often on a large repo (during build) #231140

Open jasonwilliams opened 1 month ago

jasonwilliams commented 1 month ago

Does this issue occur when all extensions are disabled?: N/A

I noticed Git goes crazy whenever I build Chromium. It shouldn't be because I'm not running any Git-related tasks while this is happening, it takes up a lot of CPU. I noticed this older issue: https://github.com/microsoft/vscode/issues/177773

I follow the same steps mentioned here and looked at the trace output. It looks like every time the build generates a new file in the out directory it triggers the git extension to run git status again. I think I've managed to calm it down a bit by setting "git.autorefresh": false,, you can see the output below.

Output:

2024-10-11 19:35:37.122 [debug] [FileEventLogger][onWorkspaceWorkingTreeFileChange] C:\chromium\out\obj\third_party\blink\renderer\core\testing\sequence_test-bcfbf884.obj.tmp
2024-10-11 19:35:37.601 [trace] [Repository][onFileChange] Skip running git status because autorefresh setting is disabled.
2024-10-11 19:35:37.601 [debug] [FileEventLogger][onWorkspaceWorkingTreeFileChange] C:\chromium\out\obj\third_party\blink\renderer\core\testing\null_execution_context-fd483ba5.obj.tmp
2024-10-11 19:35:38.001 [trace] [Repository][onFileChange] Skip running git status because autorefresh setting is disabled.
2024-10-11 19:35:38.001 [debug] [FileEventLogger][onWorkspaceWorkingTreeFileChange] C:\chromium\out\obj\third_party\blink\renderer\core\core_hot\selector_query.obj
2024-10-11 19:35:38.001 [trace] [Repository][onFileChange] Skip running git status because autorefresh setting is disabled.
2024-10-11 19:35:38.001 [debug] [FileEventLogger][onWorkspaceWorkingTreeFileChange] C:\chromium\out\obj\third_party\blink\renderer\core\core_hot\selector_query-0130c7b5.obj.tmp
2024-10-11 19:35:38.635 [trace] [Repository][onFileChange] Skip running git status because autorefresh setting is disabled.
thousands more...

Despite it skipping this still looks like a bug, the out directory is in my gitignore so it shouldn't be doing anything on changes within this directory at all anyway. Should there be logic added to here to not trigger git commands if the file changes are in an ignored repository?

Using autorefresh false is a workaround to the problem but not a proper solution as I do want git to update when genuine files have changed. Maybe either the git extension should be fixed, or the built-in workspace watcher has a config to not watch ignored folders.

Steps to Reproduce:

  1. Load Chromium in VS Code
  2. Build Chromium
  3. Git activity goes super high in task manager (parent process being VS Code)
lszomoru commented 1 month ago

You can also add the out folder to the watcher exclude list using the files.watcherExclude setting.

jasonwilliams commented 1 month ago

You can also add the out folder to the watcher exclude list using the files.watcherExclude setting.

Thanks @lszomoru

Do you know why VSCode still watches gitignored folders? Is this intentional? Or the logic wasn't added to ignore them. Even if the watching is required, having git fire "git status" on ignored folders is certainly a bug (due to there being no change).

It seems like this should be off by default, rather than developers needing to explicitly set this. It is also unnecessarily using a lot of resource when builds happen. This took me a while to figure out, so I'm sure other developers have fallen into this issue without knowing why it's happening.

lszomoru commented 1 month ago

Looking at the code, there are two event listeners set up:

  1. workspace folder (except .git folder)
  2. .git folder

At the moment the workspace folder listener does not factor in the .gitignore file, but it probably should.