ValueTask<T>
A cheaper alternative to Task<T> that avoids an allocation when an async method usually finishes synchronously, such as a cache hit.
In more detail
It comes with rules: await it exactly once, never store it and never block on it. Default to Task<T> and switch only when a profiler shows the allocation matters.
Related terms
- Task — The .NET type representing an operation that may still be running and will eventually complete with a result, an exception or cancellation.
- allocation — Reserving memory for a new object on the heap.
- hot path — Code that runs very often, such as on every request, where small costs add up.
- profiler — A tool that records where a running program spends its time or allocates memory.
Taught in
- Async and Await: Managing Concurrency — Modern .NET Core, C# & Enterprise Microservices