Introduction Part of my job on the .NET Team is to improve the performance of existing .NET libraries. My current goal is to identify performance bottlenecks in ML.NET and recognize common performance issues that should be addressed by .NET framework. In this blog post, I am describing how I approach sample performance problem using available free .NET tools and best practices for performance engineering.| adamsitnik.com
tl;dr Pass and return by reference to avoid large struct copying. It’s type and memory safe. It can be even faster than unsafe! Introduction Since C# 1.0 we could pass arguments to methods by reference. It means that instead of copying value types every time we pass them to a method we can just pass them by reference. It allows us to overcome one of the very few disadvantages of value types which I described in my previous blog post “Value Types vs Reference Types”. Passing is not enoug...| adamsitnik.com
tl;dr Use Span to work with ANY kind of memory in a safe and very efficient way. Simplify your APIs and use the full power of unmanaged memory! Contents Introduction Introduction C# gives us great flexibility when it comes to using different kinds of memory. But the majority of the developers use only the managed one. Let’s take a brief look at what C# has to offer for us: Stack memory - allocated on the Stack with the stackalloc keyword. Very fast allocation and deallocation. The size of t...| adamsitnik.com