Reservoir 1.10.0

dotnet add package Reservoir --version 1.10.0
                    
NuGet\Install-Package Reservoir -Version 1.10.0
                    
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="Reservoir" Version="1.10.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Reservoir" Version="1.10.0" />
                    
Directory.Packages.props
<PackageReference Include="Reservoir" />
                    
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 Reservoir --version 1.10.0
                    
#r "nuget: Reservoir, 1.10.0"
                    
#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 Reservoir@1.10.0
                    
#: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=Reservoir&version=1.10.0
                    
Install as a Cake Addin
#tool nuget:?package=Reservoir&version=1.10.0
                    
Install as a Cake Tool

Reservoir

Stop allocating the same thing twice.

Reservoir is thread-safe object pooling for .NET with 0 B warm paths and bounded shared retention. It ships as a small runtime library with public, library-friendly types and specialized generic policies.

NuGet CI/CD License: MIT

dotnet add package Reservoir

Requires a .NET Standard 2.0-compatible runtime or later

Why Reservoir?

  • Zero general-purpose pool allocations when warm. ObjectPool<T,TPolicy> rent and return reuse fixed slots without allocating nodes. Legacy collection fallbacks may trim or replace backing storage.
  • Bounded retention. You choose the maximum idle-object count. Every rental mode returns to the same bounded store, so idle objects never accumulate per thread.
  • Capacity-aware storage. Cache-line-separated slots keep small pools fast; dense striped storage keeps large async working sets scalable.
  • Library-friendly delivery. One public assembly identity flows normally through PackageReference dependency graphs.
  • Scoped ownership. Stack-only leases return rentals automatically when synchronous work leaves scope.

Rent. Work. Return.

Define lifecycle behavior as a struct policy so the JIT can specialize and inline it:

using Reservoir;

var pool = new ObjectPool<Buffer, BufferPolicy>(maxCapacity: 64);

using var lease = pool.RentScoped(out Buffer buffer);
buffer.Write(payload);

sealed class Buffer
{
    public int Length { get; set; }
    public void Write(ReadOnlySpan<byte> value) => Length += value.Length;
}

readonly struct BufferPolicy : IPooledObjectPolicy<Buffer>
{
    public Buffer Create() => new();

    public bool TryReset(Buffer buffer)
    {
        buffer.Length = 0;
        return true;
    }

    public void Destroy(Buffer buffer) { } // No resources to release.
}

Create() handles a miss. TryReset() prepares an object for reuse or returns false to discard it. Destroy() releases discarded objects. Every netstandard2.0 policy must implement it; modern targets provide default IDisposable cleanup when it is omitted. The scoped lease guarantees return when control leaves the synchronous scope and returns to the same bounded store as manual rentals.

Breaking policy migration: Destroy(T) now belongs to IPooledObjectPolicy<T> on every target. Rebuild existing netstandard2.0 consumers and change explicit IPooledObjectDestroyPolicy<T>.Destroy implementations to IPooledObjectPolicy<T>.Destroy. See the migration guide.

For performance-critical synchronous code, prefer RentScoped(out T) over repeated lease.Value access, which validates ownership on every read. Manual rental is required when work crosses an await. Measure on target hardware when nanoseconds matter.

For work that crosses an await, use Rent() and return the object in finally. See the quick start for both patterns.

Pools included

Reservoir includes ready-to-use pools for:

List<T> · Dictionary<TKey,TValue> · HashSet<T> · Queue<T> · Stack<T> · StringBuilder · CancellationTokenSource

List<int> values = ListPool<int>.Shared.Rent();
try
{
    values.Add(42);
    Consume(values);
}
finally
{
    ListPool<int>.Shared.Return(values);
}

Collections return empty. Oversized backing stores are discarded instead of retained. Each pool exposes a shared instance and constructors for custom limits.

For synchronous scopes, RentScoped returns the collection automatically:

using ListPool<int>.Lease lease = ListPool<int>.Shared.RentScoped(out List<int> values);
values.Add(42);
Consume(values);

The lease is stack-only and cannot cross an await. Manual Rent and Return keep using the bounded shared pool for asynchronous ownership.

CancellationTokenSourcePool.RentScoped offers the same scoped ownership while preserving source reset and disposal semantics. Use Rent() or RentLinked() when ownership crosses an async boundary.

The ownership rule

Returning an object transfers ownership to the pool. Do not touch it, return it twice, or return it to another pool.

Another thread may rent the same object immediately. Read the complete ownership rules.

Measured, not promised

BenchmarkDotNet 0.15.8 .NET 10.0, .NET 10.0.13, Linux Ubuntu 24.04.5 LTS, INTEL XEON PLATINUM 8573C:

Method Mean Ratio Allocated
new 20.25 ns 1.00 304 B
Reservoir 18.65 ns 0.92 0 B
Microsoft.Extensions.ObjectPool 18.77 ns 0.93 0 B
ConcurrentBag<T> pool 56.62 ns 2.80 0 B

Allocation measurements apply to the published workloads and their recorded runtime and job. Timings vary by machine; compare methods within the same run.

See all benchmark results and reproduction instructions. Run the full suite on a GitHub Actions ubuntu-latest runner:

gh workflow run benchmarks.yml --ref main -f 'filter=*' -f job=short

For a bounded setup check followed by a short measurement, select one warm rent/return benchmark on .NET 8 and .NET 10:

gh workflow run benchmarks.yml --ref main -f 'filter=*.ObjectPoolBenchmarks.RentReturn' -f job=short

The workflow first runs --job Dry to check compilation and execution; Dry results are not performance measurements. It then runs --job Short. Do not add --apples: BenchmarkDotNet 0.15.8 combines it with OperationsPerInvoke in a way that makes batched contention cases effectively unbounded. Use Benchmark comparison with explicit baseline and candidate SHAs for performance acceptance; local timings are diagnostic only.

When it fits

Choose Reservoir when you want bounded shared custom-object reuse, struct-policy specialization, scoped leases, or capacity-aware storage.

Use ArrayPool<T> for raw arrays. Use Microsoft.Extensions.ObjectPool when integration with Microsoft Extensions abstractions matters more than Reservoir's specialized policies and leases.

Go deeper

Documentation · Installation · API guide · Design notes

Reservoir is available under the MIT license.

Product 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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Reservoir:

Package Downloads
Kevlar

Kevlar is a fast, allocation-conscious resilience library for .NET: retries, circuit breakers, timeouts, rate limiting, concurrency limiting, hedging and fallbacks, composed through one fluent Shield API.

Dekaf

High-performance, pure C# Apache Kafka client library for .NET

Respire

Fast, modern RESP client for Redis, Valkey, KeyDB, and other RESP-compatible servers.

Respire.Compression.Zstd

Optional bounded Zstandard value compression for Respire.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.10.0 2,664 10/28/2026
1.9.1 146,427 9/13/2026
1.9.0 115 9/13/2026
1.8.0 88,777 9/9/2026
1.7.0 304 9/7/2026
1.6.10 170 9/6/2026
1.6.7 2,403 9/5/2026
1.6.3 142 9/2/2026
1.6.0 3,081 9/1/2026
1.5.0 159 9/1/2026
1.4.0 94,515 8/13/2026
1.3.0 180 8/13/2026
1.2.3 218 8/13/2026
1.2.0 142 8/13/2026
1.1.2 142 8/12/2026
1.1.0 133 8/12/2026
1.0.1 150 8/12/2026
0.3.5 220 8/12/2026
0.3.3 186 8/12/2026
0.3.0 195 8/12/2026
Loading failed