Most developers replace Task with ValueTask expecting instant performance gains.
The truth: misusing ValueTask can actually make your code slower and more fragile.
ValueTask shines only when:
-
The result is often synchronous
-
Allocation pressure matters (high-throughput paths)
public ValueTask<int> GetCachedValueAsync()
{
if (_cache.TryGetValue("x", out int value))
return new ValueTask<int>(value);
return new ValueTask<int>(LoadFromDbAsync());
}
Why it matters:ValueTask avoids heap allocation only when it returns synchronously.
If you always await async work → stick to Task.
Mistake to avoid:
await valueTask; await valueTask; // ❌ Undefined behavior
Use it surgically, not everywhere.



