Why use ValueTask?
April 10, 2021
Allocations and Scalability
Task
is a reference type, which means every time you await a task, it is allocated on the heap. As in many applications today, you are likely to have a method in your code that either runs synchronously or asynchronously depending on a condition, like whether or not some data is already stored in memory or it needs to be loaded from a longer running I/O operation. A common example in a web application would be storing infrequently changing data into a caching layer to increase the performance of subsequent reads of that data.