dotnet-format is very slow on larger repos
See original GitHub issueon our repository (https://github.com/xSke/PluralKit), dotnet-format will take between 4 and 8 seconds to run, even when no changes need to be applied.
I saw #757 but I’m not sure if it’s related, thus the new issue.
here’s a -v diag
logging of a particularly bad run:
$ dotnet-format -v diag
The dotnet format version is '5.1.225507+756d5a1c121be3e57e924788af64aa5607dc24e1'.
The dotnet runtime version is '5.0.9'.
The dotnet CLI version is '5.0.400'.
Using MSBuild.exe located in '/home/spiral/.dotnet/sdk/5.0.400/'.
Formatting code files in workspace '/home/spiral/sources/pluralkit/PluralKit.sln'.
Loading workspace.
Project PluralKit.Bot is using configuration from '/home/spiral/sources/pluralkit/.editorconfig'.
Project PluralKit.Bot is using configuration from '/home/spiral/sources/pluralkit/PluralKit.Bot/obj/Debug/net5.0/PluralKit.Bot.GeneratedMSBuildEditorConfig.editorconfig'.
Project PluralKit.Bot is using configuration from '/home/spiral/.dotnet/sdk/5.0.400/Sdks/Microsoft.NET.Sdk/analyzers/build/config/AnalysisLevel_5_Default.editorconfig'.
Project PluralKit.Core is using configuration from '/home/spiral/sources/pluralkit/.editorconfig'.
Project PluralKit.Core is using configuration from '/home/spiral/sources/pluralkit/PluralKit.Core/obj/Debug/net5.0/PluralKit.Core.GeneratedMSBuildEditorConfig.editorconfig'.
Project PluralKit.Core is using configuration from '/home/spiral/.dotnet/sdk/5.0.400/Sdks/Microsoft.NET.Sdk/analyzers/build/config/AnalysisLevel_5_Default.editorconfig'.
Project PluralKit.API is using configuration from '/home/spiral/sources/pluralkit/.editorconfig'.
Project PluralKit.API is using configuration from '/home/spiral/sources/pluralkit/PluralKit.API/obj/Debug/net5.0/PluralKit.API.GeneratedMSBuildEditorConfig.editorconfig'.
Project PluralKit.API is using configuration from '/home/spiral/.dotnet/sdk/5.0.400/Sdks/Microsoft.NET.Sdk/analyzers/build/config/AnalysisLevel_5_Default.editorconfig'.
Project PluralKit.Tests is using configuration from '/home/spiral/sources/pluralkit/.editorconfig'.
Project PluralKit.Tests is using configuration from '/home/spiral/sources/pluralkit/PluralKit.Tests/obj/Debug/net5.0/PluralKit.Tests.GeneratedMSBuildEditorConfig.editorconfig'.
Project PluralKit.Tests is using configuration from '/home/spiral/.dotnet/sdk/5.0.400/Sdks/Microsoft.NET.Sdk/analyzers/build/config/AnalysisLevel_5_Default.editorconfig'.
Project Myriad is using configuration from '/home/spiral/sources/pluralkit/.editorconfig'.
Project Myriad is using configuration from '/home/spiral/sources/pluralkit/Myriad/obj/Debug/net5.0/Myriad.GeneratedMSBuildEditorConfig.editorconfig'.
Project Myriad is using configuration from '/home/spiral/.dotnet/sdk/5.0.400/Sdks/Microsoft.NET.Sdk/analyzers/build/config/AnalysisLevel_5_Default.editorconfig'.
Complete in 4845ms.
Determining formattable files.
Complete in 1144ms.
Running formatters.
Complete in 1146ms.
Formatted 0 of 309 files.
Format complete in 7138ms.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:9 (5 by maintainers)
Top Results From Across the Web
UI Performance very slow just navigating code.
When navigating a simple solution of 2 .NET 5 projects with 20 odd files everything is very slow to open. Trying to debug...
Read more >Looking for a community "standard" .editorconfig with ...
In CI we are running both dotnet format AND running the ReSharper ... is slow due to his nature) - prepare good machine...
Read more >Manage and store large files in Git - Azure Repos
Recommendations on how to manage large binary files in Git, Visual Studio, and Team Foundation Server.
Read more >Is Your VS Code Extension Slow? Here's How to Speed it Up!
One possible cause is the number of files or the size of the extension. Some extensions have so much functionality in them that...
Read more >Optimize GitLab for large repositories
This strategy reduces the amount of data to transfer and does not really impact the operations that you might do on a repository...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just wanted to share some comments from #1479
Two things go into why Style and Analyzer operations are slower.
First, they require that we have correct semantic information about your code. To do this we rely on MSBuild performing a design-time build where we can know the exact set of code files as well as what references to include with each project. This is equivalent to what Visual Studio or OmniSharp does when opening a project/solution. It is less costly than a full compile, but it can take anywhere from seconds to minutes depending on the size of your solution.
Second, we have to actually run the analyzers and apply code fixes. Running analyzers requires additional in-memory compilations. The results of one analysis become invalid as we apply code fixes from earlier analysis.
We have discussed alternate ways to speed up populating our workspace. Ultimately MSBuild will be involved at some point because .NET builds are so highly customizable the only way not to be wrong is to have MSBuild do the work.
We are not committing to either approach today, but know that this a problem that we are thinking on.
I have been investigating
dotnet format
slowness in our large solution. Here is what I’ve found out so far:dotnet format whitespace --folder
is much faster assuming you are using .Net 6 (with the new version ofdotnet format
) and are only interested inwhitespace
formatting. If you needstyle
andanalyzers
, things get much slower due to compilation.dotnet format
under a specific project instead of the whole solution helps. For example,dotnet format Solution.sln --include SomeProject/SomeFile.cs
is much slower thandotnet format SomeProject/SomeProject.csproj --include SomeProject/SomeFile.cs
for some reason. Of course this workaround is only useful if you are doing agit diff
to format only affected files in a branch. I wrote a simple bash script to group modified files by project and rundotnet format
concurrently for each affected project with--include <path>
option. It helped reduce the total runtime from more than 2 mins to under 1 min in our solution assuming a couple of files are modified under a few different projects. We do needstyle
andanalyzers
so can’t use the fastwhitespace
command with the--folder
option.I suspect redundant compilation (due to referenced projects getting built/analyzed multiple times) is the root cause for the slowness but I am not sure yet. Needs more debugging