Introduction to the High Performance package
CommunityToolkit.HighPerformance contains helpers and extensions to work in high-performance scenarios. This package can be installed through NuGet, and it has the following multi-targets:
- .NET Standard 2.0
- .NET Standard 2.1
- .NET 6
- .NET 7
This means that you can use it from anything from UWP or legacy .NET Framework applications, games written in Unity, cross-platform mobile applications using Xamarin, to .NET Standard libraries and modern .NET 6 and .NET 7 applications. The API surface is almost identical in all cases, and lots of work has been put into backporting as many features as possible to older targets like .NET Standard 2.0. Except for some minor differences, you can expect the same APIs to be available on all target frameworks. The reason why multi-targeting has been used is to allow the package to leverage all the latest APIs on modern runtimes (like .NET 7) whenever possible, while still offering most of its functionalities to all target platforms.
To install the package from within Visual Studio:
In Solution Explorer, right-click on the project and select Manage NuGet Packages. Search for CommunityToolkit.HighPerformance and install it.
Add a using or Imports directive to use the new APIs:
Code samples are available in the other docs pages for the MVVM Toolkit, and in the unit tests for the project.
When should I use this package?
As the name suggests, the High Performance package contains a set of APIs that are heavily focused on optimization. All the new APIs have been carefully crafted to achieve the best possible performance when using them, either through reduced memory allocation, micro-optimizations at the assembly level, or by structuring the APIs in a way that facilitates writing performance oriented code in general.
This package makes heavy use of APIs such as:
If you are already familiar with these APIs or even if you're just getting started with writing high performance code in C# and want a set of well tested helpers to use in your own projects, have a look at what's included in this package to see how you can use it in your own projects!
Where to start?
Here are some APIs you could look at first, if you were already using one of those types mentioned above:
Memory2D<T>, for a
Memory<T>-like abstraction over 2D memory
SpanOwner<T>, if you were using
StringPool, for an
ArrayPool<T>-like type to cache
ParallelHelper, if you were using
You can find more examples in the unit tests.
Submit and view feedback for