2주 전 · Aug 8, 2026 1:10 AM
Why System.IO.Pipelines (the engine behind ASP.NET Core Kestrel) beats traditional Stream and byte[] buffers:
- Memory Management: Automatically manages buffer pooling and zero-copy slicing.
- Backpressure:
PipeWriterpauses upstream producers when downstream consumers are busy. - Line/Packet Parsing:
CSHARP
while (true)
{
ReadResult result = await reader.ReadAsync();
ReadOnlySequence<byte> buffer = result.Buffer;
while (TryReadLine(ref buffer, out ReadOnlySequence<byte> line))
{
ProcessLine(line);
}
reader.AdvanceTo(buffer.Start, buffer.End); // Tells pipeline which bytes were consumed!
if (result.IsCompleted) break;
}