Soenneker.Sets.Concurrent.Bounded 4.0.15

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

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Sets.Concurrent.Bounded

A high-performance bounded concurrent set for .NET

Soenneker.Sets.Concurrent.Bounded provides a thread-safe concurrent set with an approximate maximum size.
It behaves similarly to a ConcurrentDictionary-backed set but automatically evicts older entries when the set grows beyond a configured limit.

Designed for high-throughput workloads where preventing unbounded memory growth is more important than strict eviction guarantees.

Typical uses include:

  • deduplication caches
  • request ID tracking
  • preventing duplicate messages
  • bounded concurrent caches
  • rate limiting helpers
  • abuse protection
  • event stream deduplication

Installation

dotnet add package Soenneker.Sets.Concurrent.Bounded

Why this library exists

The .NET ecosystem lacks a simple bounded concurrent set.

Existing options have tradeoffs:

Collection Problem
ConcurrentDictionary Unbounded growth
HashSet Not thread-safe
MemoryCache Heavy for simple dedupe use cases
LRU caches Often require locks or background eviction

BoundedConcurrentSet provides a lightweight alternative optimized for:

  • high concurrency
  • predictable memory usage
  • low allocation
  • minimal locking

Features

✔ High-throughput concurrent operations ✔ Approximate size bounding ✔ Opportunistic eviction of older entries ✔ Lock-minimized design ✔ Low allocation footprint ✔ Safe for heavy multi-threaded workloads


Example

using Soenneker.Sets.Concurrent.Bounded;

var set = new BoundedConcurrentSet<string>(maxSize: 1000);

set.TryAdd("alpha");
set.TryAdd("beta");

bool exists = set.Contains("alpha");

set.TryRemove("beta");

string[] snapshot = set.ToArray();

Configuration

var set = new BoundedConcurrentSet<string>(
    maxSize: 1000,
    capacityHint: 1000,
    trimBatchSize: 64,
    trimStartOveragePercent: 5
);
Parameter Description
maxSize Target maximum number of elements
capacityHint Initial capacity hint for the dictionary
trimBatchSize Number of eviction attempts per trim cycle
trimStartOveragePercent Allowed overage before trimming begins

Performance Characteristics

Operation Complexity
TryAdd O(1) average
Contains O(1)
TryRemove O(1)

Eviction work is bounded per call, preventing long latency spikes.

Internally the structure uses:

  • concurrent dictionary indexing
  • opportunistic FIFO-like eviction
  • generation tokens to avoid stale scans
  • atomic counters for approximate size tracking

When to use this

Use this collection when you need:

  • a bounded concurrent set
  • deduplication tracking
  • a lightweight concurrent cache
  • to prevent unbounded memory growth

Good examples:

  • deduplicating phone numbers
  • tracking recent request IDs
  • preventing duplicate events
  • guarding against repeated API calls

Thread Safety

All operations are fully thread-safe.

The implementation is designed for high-concurrency environments and does not require external locking.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Sets.Concurrent.Bounded:

Package Downloads
Soenneker.Deduplication.Bounded

A thread-safe high-performance bounded size deduplication utility for .NET.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.15 96 3/13/2026
4.0.14 33 3/13/2026
4.0.13 31 3/12/2026
4.0.12 34 3/12/2026
4.0.11 31 3/12/2026
4.0.10 262 3/11/2026
4.0.9 41 3/11/2026
4.0.8 38 3/10/2026
4.0.7 148 3/10/2026
4.0.6 71 3/10/2026
4.0.5 77 3/9/2026
4.0.4 78 3/9/2026
4.0.3 77 3/9/2026
4.0.2 273 3/5/2026
4.0.1 84 3/5/2026