|
1 | 1 | # KZDev.PerfUtils |
2 | 2 |
|
3 | | -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. As well as the `StringBuilderCache` which allows better performance when using `StringBuilder` instances, and the `InterlockedOps` class, which provides additional atomic thread-safe operations to extend the functionality of the `Interlocked` class in the .NET Class Library. |
| 3 | +This repository contains the ['KZDev.PerfUtils'](https://www.nuget.org/packages/KZDev.PerfUtils) NuGet package, which provides the following high-performance utilities: |
| 4 | + |
| 5 | +- **MemoryStreamSlim**: A memory-efficient, high-performance replacement for the MemoryStream class, offering significant benefits for large or frequently used streams. |
| 6 | +- **StringBuilderCache**: A utility for caching StringBuilder instances to improve performance in high-throughput scenarios. |
| 7 | +- **InterlockedOps**: A set of additional atomic thread-safe operations that extend the functionality of the Interlocked class in the .NET Class Library. |
| 8 | + |
| 9 | +## Performance Highlights |
| 10 | + |
| 11 | +This sampling of performance benchmarks clearly demonstrates the advantages of using the KZDev.PerfUtils package: |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +For more details, refer to the benchmark related pages in the [documentation](https://kzdev-net.github.io/kzdev.perfutils/). |
4 | 18 |
|
5 | 19 | ## Features |
6 | 20 |
|
7 | | -`MemoryStreamSlim` is a drop-in replacement for the `MemoryStream` class that provides the following benefits: |
| 21 | +### MemoryStreamSlim |
| 22 | + |
| 23 | +`MemoryStreamSlim` is a drop-in replacement for the **MemoryStream** class, offering the following advantages: |
| 24 | + |
| 25 | +- **Improved Throughput**: Outperforms the standard MemoryStream in terms of throughput. |
| 26 | +- **Reduced Memory Traffic**: Significantly lowers memory traffic and garbage collection compared to the standard MemoryStream. |
| 27 | +- **Eliminates LOH Fragmentation**: Prevents Large Object Heap (LOH) fragmentation caused by frequent use and release of single-byte arrays. |
| 28 | +- **API Compatibility**: Provides the same API as MemoryStream, with minor differences in the constructor. |
| 29 | +- **Optional Native Memory Storage**: Allows the use of native memory for storage, further reducing GC pressure and increasing flexibility. |
| 30 | + |
| 31 | +### StringBuilderCache |
8 | 32 |
|
9 | | -* Throughput performance is better than the standard `MemoryStream`. |
10 | | -* Much lower memory traffic and far fewer garbage collections than the standard `MemoryStream`. |
11 | | -* Eliminates Large Object Heap (LOH) fragmentation caused by frequent use and release of single-byte arrays used by the standard `MemoryStream`. |
12 | | -* Simple replacement for `MemoryStream` with the same API, other than the constructor. |
13 | | -* Optionally allows using native memory for storage, which allows even more flexibility to minimize GC pressure. |
| 33 | +`StringBuilderCache` is a static class that provides a thread-safe cache of StringBuilder instances, reducing allocations and deallocations in high-throughput scenarios. Key features include: |
14 | 34 |
|
15 | | -`StringBuilderCache` is a static class that provides a thread-safe cache of `StringBuilder` instances to reduce the number of allocations and deallocations of `StringBuilder` objects in high-throughput scenarios with simple operations: |
| 35 | +- **Acquire**: Retrieve a StringBuilder instance from the cache. |
| 36 | +- **Release**: Return a StringBuilder instance to the cache. |
| 37 | +- **GetStringAndRelease**: Retrieve the string from a StringBuilder instance and return it to the cache. |
| 38 | +- **GetScope**: Use a using-scoped StringBuilder instance, which is automatically returned to the cache when the scope is exited. |
| 39 | +- **Monitoring**: Leverages the .NET runtime's Events feature for detailed cache management and monitoring. |
16 | 40 |
|
17 | | -* Acquire : Get a `StringBuilder` instance from the cache. |
18 | | -* Release : Return a `StringBuilder` instance to the cache. |
19 | | -* GetStringAndRelease : Get the string from a `StringBuilder` instance and return it to the cache. |
20 | | -* GetScope : Get a `using` scoped `StringBuilder` instance from the cache and return it to the cache when the scope is exited. |
21 | | -* Monitoring with `Events` feature of the .NET runtime for detailed cache management. |
| 41 | +### InterlockedOps |
22 | 42 |
|
23 | | -`InterlockedOps` is a static class providing the following thread-safe atomic operations: |
| 43 | +`InterlockedOps` is a static class that provides additional thread-safe atomic operations for integer types, including: |
24 | 44 |
|
25 | | -* Xor : Exclusive OR operation on any integer types. |
26 | | -* ClearBits : Clear bits on any integer types. |
27 | | -* SetBits : Set bits on any integer types. |
28 | | -* ConditionAnd : Conditionally update bits using an AND operation on any integer types. |
29 | | -* ConditionOr : Conditionally update bits using an OR operation on any integer types. |
30 | | -* ConditionXor : Conditionally update bits using an XOR operation on any integer types. |
31 | | -* ConditionClearBits : Conditionally clear bits on any integer types. |
32 | | -* ConditionSetBits : Conditionally set bits on any integer types. |
| 45 | +- **Xor**: Perform an exclusive OR operation. |
| 46 | +- **ClearBits**: Clear specific bits. |
| 47 | +- **SetBits**: Set specific bits. |
| 48 | +- **ConditionAnd**: Conditionally update bits using an AND operation. |
| 49 | +- **ConditionOr**: Conditionally update bits using an OR operation. |
| 50 | +- **ConditionXor**: Conditionally update bits using an XOR operation. |
| 51 | +- **ConditionClearBits**: Conditionally clear specific bits. |
| 52 | +- **ConditionSetBits**: Conditionally set specific bits. |
33 | 53 |
|
34 | 54 | ## Documentation |
35 | 55 |
|
36 | | -Full documentation for the package is available on the [PerfUtils Documentation](https://kzdev-net.github.io/kzdev.perfutils/) page. |
| 56 | +Comprehensive documentation for the package is available on the [PerfUtils Documentation](https://kzdev-net.github.io/kzdev.perfutils/) page. |
37 | 57 |
|
38 | 58 | ## Future Features |
39 | 59 |
|
40 | | -The roadmap plan for this package is to add several additional helpful performance focused utilities as time allows. |
| 60 | +The roadmap for this package includes plans to add additional performance-focused utilities as time allows. |
41 | 61 |
|
42 | 62 | ## Contribution Guidelines |
43 | 63 |
|
44 | | -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: |
| 64 | +At this time, external pull requests are not being accepted. However, feedback and suggestions are welcome through the following channels: |
45 | 65 |
|
46 | | -- **Feature Requests:** Please use GitHub Discussions to discuss 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. |
47 | | -- **Bug Reports:** If you encounter any issues, feel free to open an issue so it can be addressed promptly. |
| 66 | +- **Feature Requests**: Use GitHub Discussions to propose new features or enhancements. This ensures alignment with the project's goals and vision before opening a feature request. |
| 67 | +- **Bug Reports**: If you encounter any issues, please open an issue on GitHub to report them. |
48 | 68 |
|
49 | | -I appreciate your understanding and look forward to collaborating with you through discussions and issue tracking. |
| 69 | +Your understanding is appreciated, and I look forward to collaborating with you through discussions and issue tracking. |
0 commit comments