Skip to content

Optimize SimplexStream by making it Memory-first - #343

Merged
Tyrrrz merged 3 commits into
primefrom
optimize-simplexstream
Jul 30, 2026
Merged

Tyrrrz merged 3 commits into
primefrom
optimize-simplexstream

Conversation

@Tyrrrz

@Tyrrrz Tyrrrz commented Jul 30, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings July 30, 2026 14:36
@codecov

codecov Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.77%. Comparing base (daa03c1) to head (3259e8a).
⚠️ Report is 1 commits behind head on prime.

Files with missing lines Patch % Lines
CliWrap/Utils/SimplexStream.cs 91.66% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SimplexStream to publish ReadOnlyMemory<byte> directly and added ValueTask-based read/write overloads with conditional compilation.
  • Renamed the completion signaling method from ReportCompletionAsync to CloseAsync and 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.

Comment thread CliWrap/Utils/SimplexStream.cs Resolved
Comment thread CliWrap.Tests/PipingSpecs.cs Resolved
@Tyrrrz
Tyrrrz requested a review from Copilot July 30, 2026 15:13
@Tyrrrz
Tyrrrz merged commit 6c81aaf into prime Jul 30, 2026
8 checks passed
@Tyrrrz
Tyrrrz deleted the optimize-simplexstream branch July 30, 2026 15:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. Writing buffer.Memory will then send more data than intended per iteration (and NextBytes will 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 using buffer.Memory.Length can increase chunk sizes unexpectedly. Slice the rented memory to 256 and use that length when computing count/writing.
                        random.NextBytes(buffer.Memory.Span);

                        var count = Math.Min(bytesRemaining, buffer.Memory.Length);
                        await destination.WriteAsync(buffer.Memory[..count], cancellationToken);

hawkeye116477 pushed a commit to hawkeye116477/CliWrap-net462 that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants