Part of #455.
Many sites format a symbol to a string per node purely to compare against a constant. Resolve the constant to an INamedTypeSymbol once at RegisterCompilationStartAction and compare with SymbolEqualityComparer instead (zero allocation, and gives a free bail-out gate when the type isn't referenced by the compilation). This is the pattern InternalsVisibleToDiagnosticsAnalyzer and ProhibitedSubstituteForUsageInTestBaseDiagnosticsAnalyzer already use correctly.
Verification: full test suite green, benchmarks show reduced allocations for TestDetection-dependent and dictionary-lookup analyzers, no change in the set of diagnostics produced.
Part of #455.
Many sites format a symbol to a string per node purely to compare against a constant. Resolve the constant to an
INamedTypeSymbolonce atRegisterCompilationStartActionand compare withSymbolEqualityComparerinstead (zero allocation, and gives a free bail-out gate when the type isn't referenced by the compilation). This is the patternInternalsVisibleToDiagnosticsAnalyzerandProhibitedSubstituteForUsageInTestBaseDiagnosticsAnalyzeralready use correctly.Helpers/TestDetection.cs:44—IsDerivedFromTestBasestring-comparesToFullyQualifiedName()per base class per node. Convert to a cached-TestBase-symbol API (accept the compilation / cached symbol) and walk withSymbolEqualityComparer. Callers:TestClassAnalysis,TestClassFieldsAnalysis,TestClassPropertyAnalysis,ProhibitedSubstituteForUsageInTestBase.ArgumentExceptionAnalysisDiagnosticsAnalyzer.cs:129— cache the 3 exception type symbolsClassVisibilityDiagnosticsAnalyzer.cs:138,179— cache theMockBase<T>symbolDebuggerDisplayAnalysisDiagnosticsAnalyzer.cs:146— cache theDebuggerDisplayAttributesymbol (also gives a compilation-start bail-out)SuppressMessageDiagnosticsAnalyzer.cs:90— cacheSystem.ReadOnlySpan<T>symbolProhibitedClassesDiagnosticsAnalyzer.cs:91,217— compare symbol identity against the already-cached type dictionary instead of re-formattingToFullyQualifiedName()(currently done twice per node)ProhibitedMethodInvocationsDiagnosticsAnalyzer.cs:165,307,348,358/ForceMethodParametersInvocationsDiagnosticsAnalyzer.cs:149/ProhibitedMethodWithStrictParametersInvocationDiagnosticsAnalyzer.cs:120— these rebuild a qualified-name string per node as the KEY into an already-cached dictionary. Re-key the caches byINamedTypeSymbol(SymbolEqualityComparer) so no string is ever formatted on the lookup path.ConstructorGenericParameterTypeDiagnosticsAnalyser.cs:147,311— same treatmentVerification: full test suite green, benchmarks show reduced allocations for
TestDetection-dependent and dictionary-lookup analyzers, no change in the set of diagnostics produced.