public sealed class HotPathAllocationAnalyzerReports a managed-heap allocation written inside a [HotPath] member.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
HotPathAttribute's own summary said it was "a contract for the allocation analyzer", and there was no allocation analyzer (#1161). An attribute that names an enforcement nobody wrote reads from a call site exactly like one that is checked, which is worse than no attribute at all. This is the enforcement; the attribute's summary now names this rule.
⚠ What it can see is one method body and nothing further. It reports the allocations that are written in the marked member — a new, an array, a boxed value, a capturing lambda, a built string — and it cannot see one inside a method that member calls. That blind spot is deliberate rather than pending: an interprocedural allocation analysis over the BCL is not something an analyzer can do at compile time, and this repository already owns the instrument that can see through a call — Vixen.Testing.Measured counts GetAllocatedBytesForCurrentThread across real work and asserts exactly zero. The two are complements: the counter catches a callee, the rule catches the edit, and the rule is the half that runs on every build over methods no test measures.
A throw is exempt. A frame that throws has already lost, and demanding a cached exception instance is how a rule teaches people to swallow errors instead.
Two shapes that look like allocations and are not, both silent on purpose: a new of a struct is bytes on the stack or in the enclosing object, and a lambda that captures nothing is cached in a static field by the compiler — including a method group over a static method, since C# 11. Reporting either would make the rule something people learn to suppress.
Fields and properties (2)
public const string DiagnosticIdThe id reported for an allocation inside a [HotPath] member.
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnosticsReturns a set of descriptors for the diagnostics that this analyzer is capable of producing.
Methods (1)
public override void Initialize(AnalysisContext context)Called once at session start to register actions in the analysis context.
Used by (2)
- AnalyzerHarnessVixen.Core.Analyzers.Tests
- HotPathAllocationAnalyzerTestsVixen.Core.Analyzers.Tests