A practitioner's guide to the four .NET primitives that eliminate allocations in hot paths: Span for stack-sliced parsing, Memory for async-compatible slices, System.IO.Pipelines for backpressure-aware streaming, and System.Threading.Channels for producer-consumer concurrency - with a full working service example that combines all four.
The profiler says your service is slow. You look at the flame graph and most of the time is in GC collections, not in your actual business logic. That's the signal that you're allocating more than you need to in the hot path.
Four primitives address this at different layers: Span for synchronous slices without heap allocation, Memory for the same across async boundaries, System.IO.Pipelines for network-level parsing without double-buffering, and System.Threading.Channels for producer-consumer pipelines without locks. This isn't an overview. I'll assume you know why string.Substring in a tight loop is a problem.…