.NET Tips and Tricks & ValueStringBuilder

03/01/2023
C#.NET

I want to showcase two of my many side projects. My .NET Tips and Tricks website, where I collect and categorize, well, tips and tricks around .NET-related topics as well as my ValueStringBuilder.

.NET Tips and Tricks

Under https://linkdotnet.github.io/tips-and-tricks/ I collect various best practices and pitfalls around various topics related to the .NET stack. Here a small screenshot:

Preview

If you have input or other ideas, you can just submit them via the underlying GitHub repository: https://github.com/linkdotnet/tips-and-tricks

ValueStringBuilder

The ValueStringBuilder is a project I started to learn better how things like Span<T>, stackalloc and ArrayPool work. A lot happened since the initial spark, which would be the blog post titled: "Create a low allocation and faster StringBuilder - Span in Action".

Not only could I have (almost) the same API as System.Text.StringBuilder, but I also managed to have almost always fewer allocations by more performance (less runtime).

Some of the APIs look like this:

using LinkDotNet.StringBuilder;

using var builder = new ValueStringBuilder(stackalloc char[128]);
builder.AppendLine("Hello dear World");
builder.AppendFormat("{0} + {1} = {2}", 1, 2, 3);

var output = builder.ToString();

As you can see the API is almost one-to-one the same as System.Text.StringBuilder. If you want to dive deeper or even collaborate check out the GitHub repository: https://github.com/linkdotnet/StringBuilder

Here a small benchmark to show the power:

|                         Method |      Mean |    Error |   StdDev | Ratio |   Gen0 |   Gen1 | Allocated | Alloc Ratio |
|------------------------------- |----------:|---------:|---------:|------:|-------:|-------:|----------:|------------:|
|            DotNetStringBuilder | 157.61 ns | 0.602 ns | 0.563 ns |  1.00 | 0.2370 | 0.0002 |    1488 B |        1.00 |
|             ValueStringBuilder | 107.15 ns | 1.134 ns | 1.005 ns |  0.68 | 0.0892 | 0.0001 |     560 B |        0.38 |
| ValueStringBuilderPreAllocated |  91.94 ns | 0.494 ns | 0.462 ns |  0.58 | 0.0892 | 0.0001 |     560 B |        0.38 |

My Blog

Last but not least, I also want to emphasize that this very blog is completely open-source and on GitHub. It is written in Blazor, offers multiple storage providers as well as commenting system and authentication stuff. Rounded off with nice unit tests written in bUnit, where I also contribute. Here are some further links:

2
An error has occurred. This application may no longer respond until reloaded. Reload x