Home

Awesome

XenoAtom.Collections ci NuGet

<img align="right" width="160px" height="160px" src="https://raw.githubusercontent.com/XenoAtom/XenoAtom.Collections/main/img/XenoAtom.Collections.png">

This .NET library offers structure-based collections optimized for high performance and minimal memory usage. It features UnsafeList<T>, UnsafeDictionary<TKey, TValue>, and UnsafeHashSet<T>. These collections are implemented as value types backed by a managed array (except for fixed capacity list UnsafeList<T>.N2 ... UnsafeList<T>.N1024), specifically designed for performance-critical scenarios where avoiding additional memory allocations for container objects is essential.

The code has been derived from the .NET Core runtime released under the MIT license.

These collections contains unsafe methods (prefixed by Unsafe) and should be used with caution.

✨ Features

📖 Usage

In general, the API is similar to the standard collections.

It is recommended to not expose in public APIs these unsafe collections but instead use them internally for performance-critical scenarios.

Here are some examples

📊 Benchmarks

Some benchmarks are available in the src\XenoAtom.Collections.Bench folder. Here are some results:

MethodMeanErrorStdDevRatio
UnsafeList<int>.Add4.807 ns0.0667 ns0.0624 ns0.79
UnsafeList<int>.N16.Add2.570 ns0.0172 ns0.0161 ns0.42
List<int>.Add6.090 ns0.0361 ns0.0338 ns1.00
MethodMeanErrorStdDevRatio
UnsafeDictionary<int, int>44.85 ns0.577 ns0.539 ns0.81
Dictionary<int, int>55.06 ns0.307 ns0.287 ns1.00
MethodParamSizeMeanErrorStdDevRatioGen0AllocatedAlloc Ratio
SortByRef36.468 ns0.0631 ns0.0590 ns0.43--0.00
Sort314.993 ns0.0419 ns0.0350 ns1.000.003864 B1.00
SortByRef830.392 ns0.1365 ns0.1277 ns0.75--0.00
Sort840.525 ns0.1555 ns0.1379 ns1.000.003864 B1.00
SortByRef1673.797 ns0.1232 ns0.1092 ns0.59--0.00
Sort16125.879 ns0.5184 ns0.4849 ns1.000.003864 B1.00
SortByRef256870.983 ns1.4083 ns1.0995 ns0.48--0.00
Sort2561,813.291 ns8.7028 ns8.1406 ns1.000.003864 B1.00

🪪 License

This software is released under the BSD-2-Clause license.

🤗 Author

Alexandre Mutel aka XenoAtom.