Repository navigation
Optimize SimplexStream by making it Memory-first - #343
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## prime #343 +/- ##
==========================================
+ Coverage 92.61% 92.77% +0.15%
==========================================
Files 26 26
Lines 1165 1162 -3
Branches 71 73 +2
==========================================
- Hits 1079 1078 -1
+ Misses 66 64 -2
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors SimplexStream to reduce copying by switching to a memory-first handoff model (passing ReadOnlyMemory<byte> directly from writer to reader) and aligns naming by renaming the completion signal method to CloseAsync.
Changes:
- Reworked
SimplexStreamto publishReadOnlyMemory<byte>directly and addedValueTask-based read/write overloads with conditional compilation. - Renamed the completion signaling method from
ReportCompletionAsynctoCloseAsyncand updated call sites. - Updated piping tests to use
MemoryPool<byte>buffers instead of allocating new byte arrays.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| CliWrap/Utils/SimplexStream.cs | Switches the internal stream buffer model to memory-first (no shared pooled buffer), adds ValueTask read/write paths, and renames completion signaling to CloseAsync. |
| CliWrap/PipeTarget.cs | Updates piping completion signaling to call CloseAsync on SimplexStream. |
| CliWrap.Tests/PipingSpecs.cs | Updates stdin piping tests to rent buffers from MemoryPool<byte> and write using Memory overloads. |
Comments suppressed due to low confidence (1)
CliWrap.Tests/PipingSpecs.cs:804
- MemoryPool.Shared.Rent(256) may return a buffer larger than 256 bytes. Using buffer.Memory.Length here can make count > 256, changing the chunking behavior vs the previous byte[256]. Slice to 256 first and use that length for both NextBytes and count.
random.NextBytes(buffer.Memory.Span);
var count = Math.Min(bytesRemaining, buffer.Memory.Length);
await destination.WriteAsync(buffer.Memory[..count], cancellationToken);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
CliWrap.Tests/PipingSpecs.cs:739
MemoryPool<byte>.Shared.Rent(256)may return a buffer larger than 256 bytes. Writingbuffer.Memorywill then send more data than intended per iteration (andNextByteswill fill more than 256 bytes). Slice the rented memory to the requested size before filling/writing.
using var buffer = MemoryPool<byte>.Shared.Rent(256);
while (true)
{
random.NextBytes(buffer.Memory.Span);
await destination.WriteAsync(buffer.Memory, cancellationToken);
CliWrap.Tests/PipingSpecs.cs:804
MemoryPool<byte>.Shared.Rent(256)may return a buffer larger than 256 bytes, so usingbuffer.Memory.Lengthcan increase chunk sizes unexpectedly. Slice the rented memory to 256 and use that length when computingcount/writing.
random.NextBytes(buffer.Memory.Span);
var count = Math.Min(bytesRemaining, buffer.Memory.Length);
await destination.WriteAsync(buffer.Memory[..count], cancellationToken);
No description provided.