Skip to content
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

Analyzers cause significant build perf hit #720

Open
mthjones opened this issue Mar 8, 2021 · 2 comments
Open

Analyzers cause significant build perf hit #720

mthjones opened this issue Mar 8, 2021 · 2 comments

Comments

@mthjones
Copy link
Member

mthjones commented Mar 8, 2021

Including these analyzers in the build causes a significant performance hit. In one solution, the performance hit is a ~50% increase in build time (a ~100% increase in csc.exe time).

Breakdown of time spent in analyzers from this package (from building with ReportAnalyzer=true):

D2L.CodeStyle.Analyzers
1:06.961   D2L.CodeStyle.Analyzers, Version=0.157.0.0, Culture=neutral, PublicKeyToken=null
    D2L.CodeStyle.Analyzers.Immutability.ImmutabilityAnalyzer = 13.889 s
    D2L.CodeStyle.Analyzers.ApiUsage.ServiceLocator.OldAndBrokenServiceLocatorAnalyzer = 11.500 s
    D2L.CodeStyle.Analyzers.ApiUsage.DangerousMemberUsages.DangerousMemberUsagesAnalyzer = 10.690 s
    D2L.CodeStyle.Analyzers.Immutability.ReadOnlyParameterAnalyzer = 6.052 s
    D2L.CodeStyle.Analyzers.ApiUsage.ConstantAttributeAnalyzer = 5.727 s
    D2L.CodeStyle.Analyzers.ApiUsage.Events.EventPublisherEventTypesAnalyzer = 3.483 s
    D2L.CodeStyle.Analyzers.ApiUsage.Events.EventHandlerLoaderTypesAnalyzer = 3.042 s
    D2L.CodeStyle.Analyzers.ApiUsage.Configs.ConfigViewerAnalyzer = 2.804 s
    D2L.CodeStyle.Analyzers.Language.DefaultValueConsistencyAnalyzer = 1.951 s
    D2L.CodeStyle.Analyzers.Language.RequireNamedArgumentsAnalyzer = 1.816 s
    D2L.CodeStyle.Analyzers.Immutability.StatelessFuncAnalyzer = 1.017 s
    D2L.CodeStyle.Analyzers.ApiUsage.Events.EventHandlersDisallowedListAnalyzer = 931 ms
    D2L.CodeStyle.Analyzers.ApiUsage.ServiceLocator.SingletonLocatorAnalyzer = 710 ms
    D2L.CodeStyle.Analyzers.ApiUsage.DependencyInjection.DependencyRegistrationsAnalyzer = 706 ms
    D2L.CodeStyle.Analyzers.ApiUsage.LaunchDarkly.FeatureDefinitionAnalyzer = 644 ms
    D2L.CodeStyle.Analyzers.ApiUsage.Logging.LoggingExecutionContextScopeBuilderAnalyzer = 590 ms
    D2L.CodeStyle.Analyzers.ApiUsage.Events.EventTypesAnalyzer = 576 ms
    D2L.CodeStyle.Analyzers.ApiUsage.Serialization.SerializerAttributeAnalyzer = 511 ms
    D2L.CodeStyle.Analyzers.ApiUsage.SystemCollectionsImmutable.ImmutableCollectionsAnalyzer = 164 ms
    D2L.CodeStyle.Analyzers.Contract.NotNullAnalyzer = 54 ms
    D2L.CodeStyle.Analyzers.ApiUsage.JsonParamBinderAttribute.JsonParamBinderAnalyzer = 24 ms
    D2L.CodeStyle.Analyzers.Language.StructShouldBeReadonlyAnalyzer = 7 ms
    D2L.CodeStyle.Analyzers.Language.AwaitedTasksAnalyzer = 5 ms
    D2L.CodeStyle.Analyzers.Build.MandatoryReferencesAnalyzer = 2 ms
    D2L.CodeStyle.Analyzers.ApiUsage.ContentPhysicalPaths.ILegacyLpContentDirectoryFullNameAnalyzer = 0 ms
    D2L.CodeStyle.Analyzers.ApiUsage.ContentPhysicalPaths.ILegacyLpContentFilePhysicalPathAnalyzer = 0 ms
    D2L.CodeStyle.Analyzers.ApiUsage.ContentPhysicalPaths.ILpContentFilePhysicalPathAnalyzer = 0 ms
    D2L.CodeStyle.Analyzers.ApiUsage.RpcAnalyzer = 0 ms
    D2L.CodeStyle.Analyzers.Language.ClassShouldBeSealedAnalyzer = 0 ms
D2L.CodeStyle.TestAnalyzers
8.914 s   D2L.CodeStyle.TestAnalyzers, Version=0.25.0.0, Culture=neutral, PublicKeyToken=null
    D2L.CodeStyle.TestAnalyzers.ServiceLocator.CustomTestServiceLocatorAnalyzer = 3.176 s
    D2L.CodeStyle.TestAnalyzers.NUnit.ConfigTestSetupStringsAnalyzer = 2.433 s
    D2L.CodeStyle.TestAnalyzers.NUnit.TestAttributeAnalyzer = 1.036 s
    D2L.CodeStyle.TestAnalyzers.NUnit.TestCaseSourceStringsAnalyzer = 913 ms
    D2L.CodeStyle.TestAnalyzers.NUnit.CategoryAnalyzer = 905 ms
    D2L.CodeStyle.TestAnalyzers.NUnit.ValueSourceStringsAnalyzer = 436 ms
@mthjones
Copy link
Member Author

mthjones commented Mar 8, 2021

There is some indication that switching to IOperation-based analyzers may significantly improve performance: dotnet/roslyn#46349

@mthjones
Copy link
Member Author

At least some of the perf issues may stem from the reason this diagnostic exists. We use Compilation.GetSemanticModel in the two slowest analyzers in D2L.CodeStyle.Analyzers and the slowest one in D2L.CodeStyle.TestAnalyzers.

May be worth investigating if these can be replaced with one of the suggestions provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant