Skip to content

Commit

Permalink
Merging 'dev' branch for release 1.1.0.
Browse files Browse the repository at this point in the history
- Update package information for version 1.1.0
- Updated github pages documentation markdown files.
- Ran new benchmarks and included the new results.
- Introduced the 'InterlockedOps' class and corresponding unit tests.
- Annotated a number of 'medium' and 'long' run tests with the proper trait marker attributes
- Refactored, removed, and replaced some unit tests for better organization
- Cleaned up a number of internal types for the MemoryStreamSlim functionality
- Added the ability for a memory segment group to expand and include new available segments instead of adding to the segment group list for performance gains.
  • Loading branch information
kzdev-net committed Oct 25, 2024
1 parent a1e2be5 commit ce0f6e0
Show file tree
Hide file tree
Showing 96 changed files with 12,587 additions and 1,343 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# KZDev.PerfUtils

This is the repository for the 'KZDev.PerfUtils' nuget package that contains the `MemoryStreamSlim` class; a high-performance, memory-efficient, and easy-to-use replacement for the `MemoryStream` class that provides particular benefits for large or frequently used streams.
This is the repository for the ['KZDev.PerfUtils'](https://www.nuget.org/packages/KZDev.PerfUtils) nuget package that contains the `MemoryStreamSlim` class; a high-performance, memory-efficient, and easy-to-use replacement for the `MemoryStream` class that provides particular benefits for large or frequently used streams.

## Features

Expand All @@ -16,11 +16,15 @@ This is the repository for the 'KZDev.PerfUtils' nuget package that contains the

The roadmap plan for this package is to add several additional helpful performance focused utilities. These will be forthcoming as time permits, so this first release is focused just on the `MemoryStreamSlim` class.

## Documentation

Full documentation for the package is available on the [PerfUtils Documentation](https://kzdev-net.github.io/kzdev.perfutils/) page.

## Contribution Guidelines

At this time, I am not accepting external pull requests. However, any feedback or suggestions are welcome and can be provided through the following channels:

- **Feature Requests:** Please use GitHub Discussions to propose new features or enhancements.
- **Feature Requests:** Please use GitHub Discussions to discuss new new features or enhancements before opening a feature request. This will help ensure that your request is in line with the project's goals and vision.
- **Bug Reports:** If you encounter any issues, feel free to open an issue so it can be addressed promptly.

I appreciate your understanding and look forward to collaborating with you through discussions and issue tracking.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace KZDev.PerfUtils.Examples
{
public class ConditionXorExample
{
private int _flags;

public bool ToggleFlags (Predicate<int> condition, int flagBits)
{
(int originalValue, int newValue) = InterlockedOps.ConditionXor(ref _flags, condition, flagBits);
return originalValue != newValue;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace KZDev.PerfUtils.Examples
{
public class ConditionClearBitsExample
{
private int _flags;

public bool ClearFlags<T> (Func<int, T, bool> condition, T conditionArgument, int flagBits)
{
(int originalValue, int newValue) = InterlockedOps.ConditionClearBits(ref _flags, condition, conditionArgument, flagBits);
return originalValue != newValue;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace KZDev.PerfUtils.Examples
{
public class XorExample
{
private int _flag;

public bool ToggleFlag ()
{
int originalValue = InterlockedOps.Xor(ref _flag, 1);
return originalValue == 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Folder Include="MemoryStreamSlim\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Src\KZDev.PerfUtils\KZDev.PerfUtils.csproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<!--
Define solution level package version properties
-->
<PropertyGroup Label="PackageVersions">
<PerfUtils-Pkg-Microsoft_Extensions_Configuration>8.0.0</PerfUtils-Pkg-Microsoft_Extensions_Configuration>
<PerfUtils-Pkg-Microsoft_Extensions_DependencyInjection>8.0.1</PerfUtils-Pkg-Microsoft_Extensions_DependencyInjection>
<PerfUtils-Pkg-Microsoft_Extensions_Hosting>8.0.1</PerfUtils-Pkg-Microsoft_Extensions_Hosting>
</PropertyGroup>
</Project>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ Intel Core i9-14900K, 1 CPU, 32 logical and 24 physical cores
```
| Method | ZeroBuffers | ExponentialBufferGrowth | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio |
|---------------------------------------------- |------------ |------------------------ |------------:|----------:|----------:|------:|--------:|-----------:|-----------:|-----------:|--------------:|------------:|
| **&#39;MemoryStream growth fill and read&#39;** | **False** | **False** | **517.92 ms** | **10.113 ms** | **9.460 ms** | **1.00** | **0.03** | **17000.0000** | **17000.0000** | **17000.0000** | **3496975.86 KB** | **1.000** |
| &#39;RecyclableMemoryStream growth fill and read&#39; | False | False | 1,994.67 ms | 19.647 ms | 18.378 ms | 3.85 | 0.08 | - | - | - | 73.64 KB | 0.000 |
| &#39;MemoryStreamSlim growth fill and read&#39; | False | False | 96.10 ms | 1.530 ms | 1.431 ms | 0.19 | 0.00 | - | - | - | 6247.39 KB | 0.002 |
| **&#39;MemoryStream growth fill and read&#39;** | **False** | **False** | **517.23 ms** | **10.047 ms** | **10.318 ms** | **1.00** | **0.03** | **17000.0000** | **17000.0000** | **17000.0000** | **3496975.86 KB** | **1.000** |
| &#39;RecyclableMemoryStream growth fill and read&#39; | False | False | 2,054.24 ms | 17.069 ms | 15.966 ms | 3.97 | 0.08 | - | - | - | 73.64 KB | 0.000 |
| &#39;MemoryStreamSlim growth fill and read&#39; | False | False | 98.48 ms | 1.957 ms | 2.254 ms | 0.19 | 0.01 | - | - | - | 6247.38 KB | 0.002 |
| | | | | | | | | | | | | |
| **&#39;MemoryStream growth fill and read&#39;** | **False** | **True** | **511.74 ms** | **6.960 ms** | **6.170 ms** | **1.00** | **0.02** | **17000.0000** | **17000.0000** | **17000.0000** | **3496975.88 KB** | **1.000** |
| &#39;RecyclableMemoryStream growth fill and read&#39; | False | True | 190.17 ms | 3.758 ms | 6.175 ms | 0.37 | 0.01 | - | - | - | 19.6 KB | 0.000 |
| &#39;MemoryStreamSlim growth fill and read&#39; | False | True | 98.83 ms | 1.939 ms | 3.345 ms | 0.19 | 0.01 | - | - | - | 6247.39 KB | 0.002 |
| **&#39;MemoryStream growth fill and read&#39;** | **False** | **True** | **526.32 ms** | **8.146 ms** | **7.620 ms** | **1.00** | **0.02** | **17000.0000** | **17000.0000** | **17000.0000** | **3496975.81 KB** | **1.000** |
| &#39;RecyclableMemoryStream growth fill and read&#39; | False | True | 193.30 ms | 3.844 ms | 4.427 ms | 0.37 | 0.01 | - | - | - | 19.6 KB | 0.000 |
| &#39;MemoryStreamSlim growth fill and read&#39; | False | True | 93.86 ms | 1.586 ms | 1.484 ms | 0.18 | 0.00 | - | - | - | 6247.33 KB | 0.002 |
| | | | | | | | | | | | | |
| **&#39;MemoryStream growth fill and read&#39;** | **True** | **False** | **520.97 ms** | **8.836 ms** | **8.265 ms** | **1.00** | **0.02** | **17000.0000** | **17000.0000** | **17000.0000** | **3496975.86 KB** | **1.000** |
| &#39;RecyclableMemoryStream growth fill and read&#39; | True | False | 3,934.99 ms | 20.300 ms | 18.989 ms | 7.55 | 0.12 | - | - | - | 73.64 KB | 0.000 |
| &#39;MemoryStreamSlim growth fill and read&#39; | True | False | 145.29 ms | 2.854 ms | 4.183 ms | 0.28 | 0.01 | - | - | - | 6247.41 KB | 0.002 |
| **&#39;MemoryStream growth fill and read&#39;** | **True** | **False** | **522.99 ms** | **7.341 ms** | **6.866 ms** | **1.00** | **0.02** | **17000.0000** | **17000.0000** | **17000.0000** | **3496975.84 KB** | **1.000** |
| &#39;RecyclableMemoryStream growth fill and read&#39; | True | False | 3,994.58 ms | 23.239 ms | 21.738 ms | 7.64 | 0.11 | - | - | - | 73.31 KB | 0.000 |
| &#39;MemoryStreamSlim growth fill and read&#39; | True | False | 144.28 ms | 2.770 ms | 3.298 ms | 0.28 | 0.01 | - | - | - | 6247.41 KB | 0.002 |
| | | | | | | | | | | | | |
| **&#39;MemoryStream growth fill and read&#39;** | **True** | **True** | **506.72 ms** | **10.088 ms** | **9.908 ms** | **1.00** | **0.03** | **17000.0000** | **17000.0000** | **17000.0000** | **3496975.84 KB** | **1.000** |
| &#39;RecyclableMemoryStream growth fill and read&#39; | True | True | 360.09 ms | 4.884 ms | 4.568 ms | 0.71 | 0.02 | - | - | - | 19.86 KB | 0.000 |
| &#39;MemoryStreamSlim growth fill and read&#39; | True | True | 146.15 ms | 2.854 ms | 4.272 ms | 0.29 | 0.01 | - | - | - | 6247.41 KB | 0.002 |
| **&#39;MemoryStream growth fill and read&#39;** | **True** | **True** | **527.70 ms** | **10.026 ms** | **9.378 ms** | **1.00** | **0.02** | **17000.0000** | **17000.0000** | **17000.0000** | **3496975.81 KB** | **1.000** |
| &#39;RecyclableMemoryStream growth fill and read&#39; | True | True | 370.41 ms | 3.702 ms | 3.282 ms | 0.70 | 0.01 | - | - | - | 19.86 KB | 0.000 |
| &#39;MemoryStreamSlim growth fill and read&#39; | True | True | 141.66 ms | 1.979 ms | 1.852 ms | 0.27 | 0.01 | - | - | - | 6247.41 KB | 0.002 |
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>MemoryStreamBenchmarks.ContinuousGrowFillAndReadThroughputBenchmarks-20241011-211140</title>
<title>MemoryStreamBenchmarks.ContinuousGrowFillAndReadThroughputBenchmarks-20241024-194941</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
Expand All @@ -24,18 +24,18 @@
<table>
<thead><tr><th>Method </th><th>ZeroBuffers</th><th>ExponentialBufferGrowth</th><th>Mean </th><th>Error</th><th>StdDev</th><th>Ratio</th><th>RatioSD</th><th>Gen0</th><th>Gen1</th><th>Gen2</th><th>Allocated</th><th>Alloc Ratio</th>
</tr>
</thead><tbody><tr><td>&#39;MemoryStream growth fill and read&#39;</td><td>False</td><td>False</td><td>517.92 ms</td><td>10.113 ms</td><td>9.460 ms</td><td>1.00</td><td>0.03</td><td>17000.0000</td><td>17000.0000</td><td>17000.0000</td><td>3496975.86 KB</td><td>1.000</td>
</tr><tr><td>&#39;RecyclableMemoryStream growth fill and read&#39;</td><td>False</td><td>False</td><td>1,994.67 ms</td><td>19.647 ms</td><td>18.378 ms</td><td>3.85</td><td>0.08</td><td>-</td><td>-</td><td>-</td><td>73.64 KB</td><td>0.000</td>
</tr><tr><td>&#39;MemoryStreamSlim growth fill and read&#39;</td><td>False</td><td>False</td><td>96.10 ms</td><td>1.530 ms</td><td>1.431 ms</td><td>0.19</td><td>0.00</td><td>-</td><td>-</td><td>-</td><td>6247.39 KB</td><td>0.002</td>
</tr><tr><td>&#39;MemoryStream growth fill and read&#39;</td><td>False</td><td>True</td><td>511.74 ms</td><td>6.960 ms</td><td>6.170 ms</td><td>1.00</td><td>0.02</td><td>17000.0000</td><td>17000.0000</td><td>17000.0000</td><td>3496975.88 KB</td><td>1.000</td>
</tr><tr><td>&#39;RecyclableMemoryStream growth fill and read&#39;</td><td>False</td><td>True</td><td>190.17 ms</td><td>3.758 ms</td><td>6.175 ms</td><td>0.37</td><td>0.01</td><td>-</td><td>-</td><td>-</td><td>19.6 KB</td><td>0.000</td>
</tr><tr><td>&#39;MemoryStreamSlim growth fill and read&#39;</td><td>False</td><td>True</td><td>98.83 ms</td><td>1.939 ms</td><td>3.345 ms</td><td>0.19</td><td>0.01</td><td>-</td><td>-</td><td>-</td><td>6247.39 KB</td><td>0.002</td>
</tr><tr><td>&#39;MemoryStream growth fill and read&#39;</td><td>True</td><td>False</td><td>520.97 ms</td><td>8.836 ms</td><td>8.265 ms</td><td>1.00</td><td>0.02</td><td>17000.0000</td><td>17000.0000</td><td>17000.0000</td><td>3496975.86 KB</td><td>1.000</td>
</tr><tr><td>&#39;RecyclableMemoryStream growth fill and read&#39;</td><td>True</td><td>False</td><td>3,934.99 ms</td><td>20.300 ms</td><td>18.989 ms</td><td>7.55</td><td>0.12</td><td>-</td><td>-</td><td>-</td><td>73.64 KB</td><td>0.000</td>
</tr><tr><td>&#39;MemoryStreamSlim growth fill and read&#39;</td><td>True</td><td>False</td><td>145.29 ms</td><td>2.854 ms</td><td>4.183 ms</td><td>0.28</td><td>0.01</td><td>-</td><td>-</td><td>-</td><td>6247.41 KB</td><td>0.002</td>
</tr><tr><td>&#39;MemoryStream growth fill and read&#39;</td><td>True</td><td>True</td><td>506.72 ms</td><td>10.088 ms</td><td>9.908 ms</td><td>1.00</td><td>0.03</td><td>17000.0000</td><td>17000.0000</td><td>17000.0000</td><td>3496975.84 KB</td><td>1.000</td>
</tr><tr><td>&#39;RecyclableMemoryStream growth fill and read&#39;</td><td>True</td><td>True</td><td>360.09 ms</td><td>4.884 ms</td><td>4.568 ms</td><td>0.71</td><td>0.02</td><td>-</td><td>-</td><td>-</td><td>19.86 KB</td><td>0.000</td>
</tr><tr><td>&#39;MemoryStreamSlim growth fill and read&#39;</td><td>True</td><td>True</td><td>146.15 ms</td><td>2.854 ms</td><td>4.272 ms</td><td>0.29</td><td>0.01</td><td>-</td><td>-</td><td>-</td><td>6247.41 KB</td><td>0.002</td>
</thead><tbody><tr><td>&#39;MemoryStream growth fill and read&#39;</td><td>False</td><td>False</td><td>517.23 ms</td><td>10.047 ms</td><td>10.318 ms</td><td>1.00</td><td>0.03</td><td>17000.0000</td><td>17000.0000</td><td>17000.0000</td><td>3496975.86 KB</td><td>1.000</td>
</tr><tr><td>&#39;RecyclableMemoryStream growth fill and read&#39;</td><td>False</td><td>False</td><td>2,054.24 ms</td><td>17.069 ms</td><td>15.966 ms</td><td>3.97</td><td>0.08</td><td>-</td><td>-</td><td>-</td><td>73.64 KB</td><td>0.000</td>
</tr><tr><td>&#39;MemoryStreamSlim growth fill and read&#39;</td><td>False</td><td>False</td><td>98.48 ms</td><td>1.957 ms</td><td>2.254 ms</td><td>0.19</td><td>0.01</td><td>-</td><td>-</td><td>-</td><td>6247.38 KB</td><td>0.002</td>
</tr><tr><td>&#39;MemoryStream growth fill and read&#39;</td><td>False</td><td>True</td><td>526.32 ms</td><td>8.146 ms</td><td>7.620 ms</td><td>1.00</td><td>0.02</td><td>17000.0000</td><td>17000.0000</td><td>17000.0000</td><td>3496975.81 KB</td><td>1.000</td>
</tr><tr><td>&#39;RecyclableMemoryStream growth fill and read&#39;</td><td>False</td><td>True</td><td>193.30 ms</td><td>3.844 ms</td><td>4.427 ms</td><td>0.37</td><td>0.01</td><td>-</td><td>-</td><td>-</td><td>19.6 KB</td><td>0.000</td>
</tr><tr><td>&#39;MemoryStreamSlim growth fill and read&#39;</td><td>False</td><td>True</td><td>93.86 ms</td><td>1.586 ms</td><td>1.484 ms</td><td>0.18</td><td>0.00</td><td>-</td><td>-</td><td>-</td><td>6247.33 KB</td><td>0.002</td>
</tr><tr><td>&#39;MemoryStream growth fill and read&#39;</td><td>True</td><td>False</td><td>522.99 ms</td><td>7.341 ms</td><td>6.866 ms</td><td>1.00</td><td>0.02</td><td>17000.0000</td><td>17000.0000</td><td>17000.0000</td><td>3496975.84 KB</td><td>1.000</td>
</tr><tr><td>&#39;RecyclableMemoryStream growth fill and read&#39;</td><td>True</td><td>False</td><td>3,994.58 ms</td><td>23.239 ms</td><td>21.738 ms</td><td>7.64</td><td>0.11</td><td>-</td><td>-</td><td>-</td><td>73.31 KB</td><td>0.000</td>
</tr><tr><td>&#39;MemoryStreamSlim growth fill and read&#39;</td><td>True</td><td>False</td><td>144.28 ms</td><td>2.770 ms</td><td>3.298 ms</td><td>0.28</td><td>0.01</td><td>-</td><td>-</td><td>-</td><td>6247.41 KB</td><td>0.002</td>
</tr><tr><td>&#39;MemoryStream growth fill and read&#39;</td><td>True</td><td>True</td><td>527.70 ms</td><td>10.026 ms</td><td>9.378 ms</td><td>1.00</td><td>0.02</td><td>17000.0000</td><td>17000.0000</td><td>17000.0000</td><td>3496975.81 KB</td><td>1.000</td>
</tr><tr><td>&#39;RecyclableMemoryStream growth fill and read&#39;</td><td>True</td><td>True</td><td>370.41 ms</td><td>3.702 ms</td><td>3.282 ms</td><td>0.70</td><td>0.01</td><td>-</td><td>-</td><td>-</td><td>19.86 KB</td><td>0.000</td>
</tr><tr><td>&#39;MemoryStreamSlim growth fill and read&#39;</td><td>True</td><td>True</td><td>141.66 ms</td><td>1.979 ms</td><td>1.852 ms</td><td>0.27</td><td>0.01</td><td>-</td><td>-</td><td>-</td><td>6247.41 KB</td><td>0.002</td>
</tr></tbody></table>
</body>
</html>
Loading

0 comments on commit ce0f6e0

Please sign in to comment.