ZeroAlloc.Analyzers
1.11.1
See the version list below for details.
dotnet add package ZeroAlloc.Analyzers --version 1.11.1
NuGet\Install-Package ZeroAlloc.Analyzers -Version 1.11.1
<PackageReference Include="ZeroAlloc.Analyzers" Version="1.11.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ZeroAlloc.Analyzers" Version="1.11.1" />
<PackageReference Include="ZeroAlloc.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ZeroAlloc.Analyzers --version 1.11.1
#r "nuget: ZeroAlloc.Analyzers, 1.11.1"
#:package ZeroAlloc.Analyzers@1.11.1
#addin nuget:?package=ZeroAlloc.Analyzers&version=1.11.1
#tool nuget:?package=ZeroAlloc.Analyzers&version=1.11.1
ZeroAlloc.Analyzers
Roslyn analyzers for modern .NET performance patterns. ZeroAlloc.Analyzers catches allocation-heavy patterns that built-in analyzers miss — FrozenDictionary opportunities, LINQ iterator overhead, boxing in loops, async state machine waste, and more — with 64 rules across 15 categories. Every rule is multi-TFM aware: rules that require a specific .NET version are automatically silenced when your project targets an older framework, so every diagnostic you see is actionable.
Installation
dotnet add package ZeroAlloc.Analyzers
Example
// warning ZA0105: Use 'TryGetValue' instead of 'ContainsKey' followed by indexer access
// Before — two dictionary lookups
if (_cache.ContainsKey(key))
return _cache[key];
// After — single lookup
if (_cache.TryGetValue(key, out var value))
return value;
// warning ZA0201: String concatenation in a loop causes repeated allocations — use StringBuilder
// Before
string result = "";
foreach (var item in items)
result += item + ", "; // allocates a new string every iteration
// After
var sb = new System.Text.StringBuilder();
foreach (var item in items)
sb.Append(item).Append(", ");
string result = sb.ToString();
Performance
On a 240-file sample project the package added a median of 1–4% to a net8.0 build, 4–5% to a net8.0 + netstandard2.0 build and 10–23% to a netstandard2.0 build, relative to the same project built without it; see Measured overhead for the method, the spread and the harness to reproduce it. Changing any file reruns the analyzers over the whole project; a build with no changes does not run them. TFM-gated rules that do not apply to your target framework add no per-file work.
| Scenario | Rules active |
|---|---|
netstandard2.0 single-TFM |
41 of 64, or 44 with the System.Memory and assembly-scanning library packages |
net8.0 single-TFM |
59 of 64, or 62 with the Configuration.Binder, Options and assembly-scanning library packages |
net8.0 + netstandard2.0 multi-TFM |
59 / 41 per TFM, or 62 / 44 with the Configuration.Binder, Options, assembly-scanning library and System.Memory packages |
net8.0, data-flow rules disabled (ZA0607, ZA0502) |
57 of 64 |
A rule counts as active when it can report with no extra packages at the target's default language version. ZA1707 and ZA1708 need the Microsoft.Extensions.Configuration.Binder and Microsoft.Extensions.Options packages. They do not run on netstandard2.0 even with those packages, because its default C# 7.3 is below their C# 12 and C# 8 gates.
See docs/performance.md for tuning tips.
Features
- 64 rules across 15 categories: Collections, Strings, Memory, Logging, Boxing, LINQ, Regex, Enums, Sealing, Serialization, Async, Delegates, Value Types, Data Layout, Native AOT
- Multi-TFM aware — rules requiring net5.0+, net6.0+, net7.0+, or net8.0+ are automatically gated; you never see a diagnostic for an API that does not exist in your target
- Code fixes included for a subset of rules — apply suggestions with one click from the IDE or via
dotnet format - Zero transitive dependency — the package is a development dependency, so
dotnet add packagemarks itPrivateAssets="all"and it does not propagate to your consumers - IDE + CLI — diagnostics surface in Visual Studio, Rider, VS Code with C# Dev Kit, and
dotnet buildoutput
Documentation
| Page | Description |
|---|---|
| Getting Started | Install the package, understand first diagnostics, IDE setup, TFM awareness |
| Configuration | Severity tuning, suppression, TFM gating, TreatWarningsAsErrors |
| Collections (ZA01xx) | FrozenDictionary, FrozenSet, TryGetValue, pre-sizing, zero-length arrays |
| Strings (ZA02xx) | StringBuilder, AsSpan, string.Create, CompositeFormat, boxing in concatenation |
| Memory (ZA03xx) | stackalloc for small buffers, ArrayPool for large temporary arrays, returning rented arrays, constant tables as spans |
| Logging (ZA04xx) | LoggerMessage source generator vs reflection-based logging |
| Boxing (ZA05xx) | Value type boxing in loops, closure allocations, defensive copies |
| LINQ (ZA06xx) | LINQ in loops, Count vs Any, indexer vs First/Last, multiple enumeration |
| Regex (ZA07xx) | GeneratedRegex source generator vs runtime regex compilation |
| Enums (ZA08xx) | HasFlag boxing, Enum.ToString allocations, GetName/GetValues in loops |
| Sealing (ZA09xx) | Class sealing for JIT devirtualization |
| Serialization (ZA10xx) | JSON source generation vs reflection-based serialization |
| Async (ZA11xx) | Elide async/await on tail calls, dispose CancellationTokenSource, Span in async |
| Delegates (ZA14xx) | Static lambda caching, closure elimination, state-passing overloads |
| Value Types (ZA15xx) | Struct GetHashCode override and IEquatable on hash keys, avoid finalizers |
| Data Layout (ZA16xx) | Cache-line aware struct field packing, false-sharing isolation |
| Native AOT (ZA17xx) | Expression.Compile, Reflection.Emit, runtime generics, reflection serializers, name-based loading, AOT-compatible libraries, configuration binding, options validation, dynamic, assembly-scanning registration |
| Build Performance | Analyzer build-time overhead, TFM gating, CI vs local configuration |
| Testing with Analyzers | Suppress warnings in tests, write Roslyn diagnostic tests, TFM-gated rule testing |
License
MIT
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.13.2 | 0 | 11/22/2026 |
| 1.13.1 | 17,447 | 11/16/2026 |
| 1.13.0 | 24,499 | 11/11/2026 |
| 1.12.0 | 18,907 | 10/29/2026 |
| 1.11.3 | 8,061 | 10/23/2026 |
| 1.11.2 | 17,068 | 10/16/2026 |
| 1.11.1 | 3,080 | 10/15/2026 |
| 1.11.0 | 17,406 | 10/10/2026 |
| 1.10.0 | 207 | 10/10/2026 |
| 1.9.0 | 1,414 | 10/9/2026 |
| 1.8.0 | 209 | 10/9/2026 |
| 1.7.0 | 260 | 10/9/2026 |
| 1.6.0 | 157 | 10/9/2026 |
| 1.5.6 | 1,002 | 10/9/2026 |
| 1.5.5 | 258 | 10/9/2026 |
| 1.5.4 | 20,993 | 9/25/2026 |
| 1.5.3 | 6,602 | 9/20/2026 |
| 1.5.2 | 1,086 | 9/19/2026 |
| 1.5.1 | 166 | 9/19/2026 |
| 1.5.0 | 11,963 | 6/27/2026 |