ZeroAlloc.Analyzers 1.3.6

dotnet add package ZeroAlloc.Analyzers --version 1.3.6
                    
NuGet\Install-Package ZeroAlloc.Analyzers -Version 1.3.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZeroAlloc.Analyzers" Version="1.3.6">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.Analyzers" Version="1.3.6" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAlloc.Analyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZeroAlloc.Analyzers --version 1.3.6
                    
#r "nuget: ZeroAlloc.Analyzers, 1.3.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZeroAlloc.Analyzers@1.3.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZeroAlloc.Analyzers&version=1.3.6
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.Analyzers&version=1.3.6
                    
Install as a Cake Tool

NuGet Build License: MIT

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 43 rules across 13 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 + indexer access.
// Before — two dictionary lookups
if (_cache.ContainsKey(key))
    return _cache[key];

// After — single lookup, zero extra allocation
if (_cache.TryGetValue(key, out var value))
    return value;
// warning ZA0201: Avoid string concatenation in loops; use StringBuilder or an interpolated string handler.
// 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

Roslyn analyzers run incrementally; on a warmed-up build only changed files are re-analyzed, so the steady-state cost is proportional to the number of files you actually edit, not your whole codebase. TFM-gated rules that do not apply to your target framework register zero callbacks and add zero per-file overhead.

Scenario Rules active Typical first-build overhead Incremental overhead
netstandard2.0 single-TFM 29 of 43 ~120 ms ~10 ms
net8.0 single-TFM 43 of 43 ~200 ms ~15 ms
net8.0 + netstandard2.0 multi-TFM 43 / 29 per TFM ~350 ms ~25 ms
net8.0, data-flow rules disabled (ZA0607, ZA0502) 41 of 43 ~160 ms ~10 ms

See docs/performance.md for tuning tips.

Features

  • 43 rules across 13 categories: Collections, Strings, Memory, Logging, Boxing, LINQ, Regex, Enums, Sealing, Serialization, Async, Delegates, Value Types
  • 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 — install with PrivateAssets="all" so the package does not propagate to your consumers
  • IDE + CLI — diagnostics surface in Visual Studio, Rider, VS Code with C# Dev Kit, and dotnet build output

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
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
Value Types (ZA15xx) Struct GetHashCode override, avoid finalizers
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

There are no supported framework assets in this package.

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.3.6 54 3/17/2026
1.3.5 39 3/16/2026
1.3.4 36 3/16/2026
1.3.3 39 3/16/2026
1.3.2 39 3/15/2026
1.3.1 175 3/13/2026
1.3.0 37 3/13/2026
1.2.0 39 3/13/2026
1.1.0 71 3/10/2026
1.0.3 100 3/9/2026
1.0.2 219 3/8/2026
1.0.1 70 3/8/2026