-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad performance in CSharpRemoveUnnecessaryImportsDiagnosticAnalyzer with System.Text.Json source generator #74761
Comments
|
Note: this is set to:
But it's unclear why. That code was added in b3476d1#diff-3c62b8ef897e66c9ff76350001c3df5de9dbb9913d8369056dedb9c7404cc8caL71 But what's odd is that the code before this point didn't seem to be asking about generated code. The only feature that did was src/Analyzers/Core/Analyzers/MakeFieldReadonly/MakeFieldReadonlyDiagnosticAnalyzer.cs So i don't know why unnecessary usings analysis was opted into that at this point. @Youssef1313 you made the change in this PR: #62895 I'm gonig to disable this for now to see what breaks. |
@CyrusNajmabadi It was existing but just refactored I think the reason may be that the analyzer should still fade out unnecessary usings in IDE. There was changes around it in #29704 (yet, it was still analyzing generated code even before that PR) |
As this is very specific to IDE, I think we shouldn't incur the performance penalty for command-line builds. But I don't know if there is currently a way to do it |
I'm very ok with this not working |
Duplicate of #72162 |
@mus65 if you add the following line to a source file, what version is printed when you build?
It's marked as a duplicate primarily because we found the report to be a red herring. Due to some design limitations, the compiler was reporting performance overhead as part of Based on the report above and the contents of the linked repo, it is my belief that the fix for the way performance data is reported from #72162 is not included in the SDK you were using in the repro case. This can be verified by getting the exact version information. |
Compiler version (.NET 9 Preview 7):
But then why is compilation a lot faster when changing |
@mus65 Thank you, I'm able to reproduce some issues with this information and will work to get those corrected. |
Issues to fix:
|
This change ensures AnalyzeSemanticModel only performs analysis when unused imports are being reported. Previously, this method would run when the only enabled diagnostic was 'EnableGenerateDocumentationFile', even though that diagnostic is unrelated to the work performed in AnalyzeSemanticModel. Discovered during investigation of dotnet#74761.
We were trying to make use of System.Text.Json source generation with a class that is pretty deeply nested with a lot of classes and properties.
We noticed that this causes a huge slowdown in build performance. While a build previously took about 5s, the source generation caused it go up to about 40s.
It seems like the generated code by System.Text.Json causes some kind of performance issue in
CSharpRemoveUnnecessaryImportsDiagnosticAnalyzer
. I created a repro below with 1000 classes, resulting in 1000 source generated files by System.Text.Json.Is there a way to disable this particular analyzer? Disabling IDE0005 in .editorconfig seems to have no effect. The only way we found to avoid this, is by disabling
EnforceCodeStyleInBuild
completely.I'm also wondering why the analyzer even analyses source generated code. Is this expected behaviour? Or is this actually not what is happening?
Version Used:
.NET 9 Preview 7. Also reproducible with .NET 8 .
Steps to Reproduce:
dotnet build -v diag | grep -B 4 -A 2 CSharpRemoveUnnecessaryImportsDiagnosticAnalyzer
. This outputs the following on my local machine:Diagnostic Id:
IDE0005: Remove unnecessary using directives
Expected Behavior:
Minimal to no impact on build performance.
Actual Behavior:
A lot of CPU time wasted in
CSharpRemoveUnnecessaryImportsDiagnosticAnalyzer
:The text was updated successfully, but these errors were encountered: