.NET Tips and Tricks & ValueStringBuilder


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:


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


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:

Three tricks with Dictionary

In this short blog post, I want to showcase two nice tricks you can do with everybody's favorite data type: the dictionary.

It is a versatile data structure, and we can make it even more versatile!

My first Post

Welcome to my blog and my first post

In this article I will show you why I created my own blog-software from scratch and why I have a blog in the first place. Short answer: I like to know how to create a blog and I like blazor. Long answer you will find in the post.

Prerendering Blazor Apps - How does it work / tips and tricks

Blazor comes with the option to prerender your webpage on the server. This works for the client-side version as well as the server side version of Blazor.

Let's have a look how does it work and what might be some pitfalls and how can we come around those.

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