.NET 5 performance improvements

What an amazing update about performance improvements in the upcoming .NET 5 by Stephen Toub!

A 1h+ read with so many amazing tidbits of information. Thank you Stephen for posting.

If you can, the article it’s definitely worth the time reading, but if not, here’s the TL;DR; version where I will extract some of the performance improvement for the things you probably are using today in your application and that will get these performance boosts with nothing else than updating your application to the new runtime.

Text operations
3-5x faster Trim(), ToUpperInvariant(), ToLowerInvariant(), Int32.ToString() than .NET FW 4.8 tanks to System.Char improvements

Regular Expressions
up to 7x improvement when using multiline expressions .
Incredible up to 20x gains for Email, Ip or Uri matches when compared to .NET FW 4.8 and 15x compared to .NET Core 3.1

Collections
2x improvement in using Dictionary<TKey,TValue> by improving the deterministic algorithm that creates the buckets that undelay the dictionary implementation. If you’re not familiar with how that works, definitely recommend reading the entire paragraph as it does an excellent job of summarizing how dictionaries work. This also applies for HashSet<T> and ConcurrentDictionary<TKey,TValue>.

Networking
The simple action of creating a Uri object from a string, is 3x times faster compared to .NET FW 4.8 . Most other actions involving Uri objects such as PathAndQuery, EscapeDataString() and UnescapeDataString() can see performance gains between 7x and 25x when dealing with Unicode strings.

Also, 3x performance improvement for HTTP/2

JSON
A lot has been done with the new System.Text.Json library starting with .NET Core 3.0, but .NET 5 brings even more. You can see improvements ranging from 2x to 5x in serializing arrays and complex types.

Async

A fascinating example of metrics based optimization. Turns out majority of times people call Task.WhenAny() they call it with just 2 tasks. Optimization in .NET 5 makes that specific case 2x faster when tasks are in still running and 10x faster if they’re already done.

The list above is definitely not an exhaustive list, just a few more common use cases that were easy to extract and digest so that everyone gets as excited as I am about this upcoming release.

Share Comments