Skip to content

Perf Phase 1: syntactic prefilters before semantic-model calls #457

Description

@credfeto

Part of #455. Depends on the benchmark baseline from the Phase 0 sub-issue.

Classic analyzer perf bug: calling GetSymbolInfo/GetTypeInfo/GetDeclaredSymbol before cheap syntactic checks (node kind, Identifier.Text, modifiers). Fix by adding a cheap syntactic prefilter before each semantic-model call. Ordered by impact:

  • ProhibitedMethodsDiagnosticsAnalyzer.cs:281-287GetTypeInfo runs on every member access before any name check. Add a static HashSet<string> of banned member names (Now, UtcNow, Today, Parse, InvariantCulture, …) tested against Name.Identifier.Text first. Biggest single win in the package.
  • ForceMethodParametersInvocationsDiagnosticsAnalyzer.cs:137 — method-name text prefilter (Serialize, SerializeAsync, Deserialize, DeserializeAsync, Received) before FindInvokedMemberSymbol
  • ProhibitedMethodInvocationsDiagnosticsAnalyzer.cs:154 — prefilter on {True, False, AddOrUpdate, GetOrAdd, Equals} before FindInvokedMemberSymbol
  • ProhibitedMethodWithStrictParametersInvocationDiagnosticsAnalyzer.cs:110 — prefilter on {Received, AddJsonFile} before FindInvokedMemberSymbol
  • ProhibitedClassesInTestAssembliesDiagnosticsAnalyzer.cs:141 — syntactic prefilter for Console receivers
  • ProhibitedSubstituteForUsageInTestBaseDiagnosticsAnalyzer.cs:187 — check syntactic name text is For before GetSymbolInfo
  • ArgumentExceptionAnalysisDiagnosticsAnalyzer.cs:73 — check objectCreation.Type identifier text against {ArgumentException, ArgumentNullException, ArgumentOutOfRangeException} before GetSymbolInfo
  • TestClassFieldsAnalysisDiagnosticsAnalyzer.cs:38 — reorder: cheap readonly/const modifier check BEFORE the semantic IsDerivedFromTestBase walk
  • TestClassPropertyAnalysisDiagnosticsAnalyzer.cs:42 — reorder: syntactic accessor-mutability check BEFORE IsDerivedFromTestBase
  • TestClassAnalysisDiagnosticsAnalyzer.cs:59 — syntactic attribute-name prefilter ({Fact, Theory, FactAttribute, TheoryAttribute}) before per-attribute GetTypeInfo, and/or gate the analyzer on IsTestAssembly() at compilation start

Verification: full test suite green, benchmarks from the Phase 0 sub-issue show reduced mean time / allocations for affected analyzers, no change in the set of diagnostics produced.

Metadata

Metadata

Assignees

Labels

AI-WorkWork for an AI AgentUrgentUrgent 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