Skip to content

Perf Phase 4: micro-optimizations and allocation trims #460

Description

@credfeto

Part of #455.

  • Remove ineffective per-syntax-node caches: ConcurrentDictionary<ParameterSyntax,…> / <MemberDeclarationSyntax,…> at ParameterName:83, ParameterOrdering:58, FileNameMustMatchType:52, OneTypePerDocument:60. A syntax node is visited exactly once per analyzer pass, so these never hit and only add dictionary overhead. (Keep the symbol-keyed caches — symbols recur, so those pay off.)
  • ParameterOrderingDiagnosticsAnalyzer.cs:80PreferredEndingOrdering.Reverse() re-materialized per parameter list; reverse once into a static field
  • ClassVisibilityDiagnosticsAnalyzer.cs:99[.. BaseClasses()] materializes a list per class node; enumerate lazily
  • Replace ForEach/FirstOrNull extension calls with plain foreach loops on hot paths (delegate + closure allocation per node)
  • Helpers/SupportedDiagnosisList.cs — single-rule overload uses ImmutableArray.Empty.Add; use a collection expression
  • Add compilation-start GetTypeByMetadataName bail-out gates to the analyzers that lack one and target types that may be absent from a compilation: ArgumentExceptionAnalysis, ClassAnalysis (BenchmarkDotNet), ClassVisibility (MockBase), DebuggerDisplayAnalysis, ForceMethodParametersInvocations, ParameterName/ParameterOrdering (ILogger), TestClass* trio (TestBase/xunit)
  • Helpers/TypeSymbolHelpers.cs:7ToFullyQualifiedName() allocates two strings per call (namespace ToDisplayString() + interpolation). After the Phase 2/3 sub-issues most hot callers should be gone; for the remainder, consider a SymbolEqualityComparer-keyed memo or eliminating the call sites entirely.

Verification: full test suite green, benchmarks show reduced allocations, no change in the set of diagnostics produced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AI-WorkWork for an AI AgentLowLow Priority

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions