HotPathGuard.Abstractions
0.2.0
dotnet add package HotPathGuard.Abstractions --version 0.2.0
NuGet\Install-Package HotPathGuard.Abstractions -Version 0.2.0
<PackageReference Include="HotPathGuard.Abstractions" Version="0.2.0" />
<PackageVersion Include="HotPathGuard.Abstractions" Version="0.2.0" />
<PackageReference Include="HotPathGuard.Abstractions" />
paket add HotPathGuard.Abstractions --version 0.2.0
#r "nuget: HotPathGuard.Abstractions, 0.2.0"
#:package HotPathGuard.Abstractions@0.2.0
#addin nuget:?package=HotPathGuard.Abstractions&version=0.2.0
#tool nuget:?package=HotPathGuard.Abstractions&version=0.2.0
HotPathGuard
HotPathGuard is a small Roslyn analyzer package for code where accidental managed allocations are correctness bugs, not just performance smells.
Mark a type or member with [HotPath], and the analyzer reports common allocation-prone constructs inside that hot path. Cold or diagnostic helpers near a hot path can be marked with [HotPathAllocationAllowed("reason")], but hot paths may not call those helpers.
Packages
| Package | Purpose |
|---|---|
HotPathGuard.Abstractions |
Public attributes used by libraries and applications. |
HotPathGuard.Analyzers |
Roslyn analyzer package that reports HPG diagnostics. |
Example
using HotPathGuard;
[HotPath]
public sealed class AudioMixer
{
public void MixFrame(ReadOnlySpan<float> input, Span<float> output)
{
// HPG001: reference-type allocation in a hot path.
var scratch = new float[1024];
}
}
Diagnostics
| ID | Title |
|---|---|
HPG001 |
Hot path contains an allocation |
HPG002 |
Hot path calls an allocating API |
HPG003 |
Hot path creates a compiler state machine |
HPG004 |
Allocation allowance requires a reason |
HPG005 |
Hot path calls a cold allocation-allowed member |
HPG006 |
Hot path method exceeds branch complexity limit |
Branch Budgets
HotPathAttribute.MaxBranches can put a simple branch-count budget on a hot-path method:
[HotPath(MaxBranches = 2)]
public int SelectVoice(int a, int b, int c)
{
if (a > 0) return a;
if (b > 0) return b;
if (c > 0) return c; // HPG006
return 0;
}
Philosophy
HotPathGuard is a guardrail, not a profiler or a formal allocation proof. It catches common source-level mistakes in code that you already know is hot: object and array creation, closures, method-group-to-delegate conversions, boxing, interpolated strings, LINQ and other known allocating APIs, async and iterator state machines, and calls into explicitly allocation-allowed members.
Build
Requires the .NET 10 SDK.
dotnet build .\HotPathGuard.slnx
dotnet test .\HotPathGuard.slnx
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on HotPathGuard.Abstractions:
| Package | Downloads |
|---|---|
|
HotPathGuard.Analyzers
Roslyn analyzers for enforcing allocation-conscious hot-path performance contracts in .NET code. |
|
|
Copper6510
Cycle-stepped MOS 6510 CPU emulation core with hardware interrupt lines and common undocumented opcode support. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Detect method-group-to-delegate conversions in hot paths.