add check to see if we need to seek before hand#1160
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request aims to improve performance and memory efficiency for buffered/forward-only stream scenarios (per issue #1105) by reducing unnecessary seek operations, pooling buffers, and adjusting tests to better represent non-seekable streams.
Changes:
- Update
BufferedSubStreamto rent its internal cache fromArrayPool<byte>.Sharedand return it on dispose. - Optimize cache refill logic to avoid unnecessary seeks when already at the correct position.
- Update
BufferReadAndSeekTestto use a forward-only stream wrapper.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/SharpCompress.Test/Streams/SharpCompressStreamTest.cs | Adjusts a test to wrap the base stream in ForwardOnlyStream to simulate non-seekable behavior. |
| src/SharpCompress/IO/SharpCompressStream.cs | Removes an unused local variable in Seek. |
| src/SharpCompress/IO/BufferedSubStream.cs | Introduces pooled buffer usage and conditional seeking in cache refill paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@adamhathcock I've opened a new pull request, #1161, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Fix ArrayPool corruption from double-disposal in BufferedSubStream
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Related to findings on #1105 by @julianxhokaxhiu
This pull request improves memory efficiency and stream handling in
BufferedSubStreamby using pooled buffers and optimizing seek operations. It also updates the test suite to better simulate forward-only stream scenarios.Memory Management Improvements:
_cacheallocation inBufferedSubStreamto useArrayPool<byte>.Shared.Rentfor buffer pooling, and ensured the buffer is returned to the pool inDisposefor reduced GC pressure. [1] [2]Performance and Stream Handling Enhancements:
RefillCacheandRefillCacheAsyncto avoid unnecessary seek operations by checking the current stream position before seeking, improving performance for sequential reads. [1] [2]Testing Improvements:
BufferReadAndSeekTestto wrap the memory stream withForwardOnlyStream, better simulating streams that do not support seeking. [1] [2]