[PR #1160] [MERGED] add check to see if we need to seek before hand #1594

Open
opened 2026-01-29 22:21:18 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/1160
Author: @adamhathcock
Created: 1/26/2026
Status: Merged
Merged: 1/26/2026
Merged by: @adamhathcock

Base: releaseHead: adam/check-if-seek


📝 Commits (8)

  • 44e4b18 add check to see if we need to seek before hand
  • a82fda9 more testing and add pooling to cache
  • ddf37e8 Initial plan
  • 8c95f86 do CanSeek first
  • 875c2d7 Fix BufferedSubStream double-dispose issue with ArrayPool
  • a0af060 Add disposal checks to RefillCache methods
  • 56d3091 Fix condition order to check CanSeek before Position
  • 7dcc13c Merge pull request #1161 from adamhathcock/copilot/sub-pr-1160

📊 Changes

3 files changed (+74 additions, -12 deletions)

View changed files

📝 src/SharpCompress/IO/BufferedSubStream.cs (+44 -10)
📝 src/SharpCompress/IO/SharpCompressStream.cs (+0 -1)
📝 tests/SharpCompress.Test/Streams/SharpCompressStreamTest.cs (+30 -1)

📄 Description

Related to findings on https://github.com/adamhathcock/sharpcompress/issues/1105 by @julianxhokaxhiu

This pull request improves memory efficiency and stream handling in BufferedSubStream by using pooled buffers and optimizing seek operations. It also updates the test suite to better simulate forward-only stream scenarios.

Memory Management Improvements:

  • Switched _cache allocation in BufferedSubStream to use ArrayPool<byte>.Shared.Rent for buffer pooling, and ensured the buffer is returned to the pool in Dispose for reduced GC pressure. [1] [2]

Performance and Stream Handling Enhancements:

  • Updated RefillCache and RefillCacheAsync to avoid unnecessary seek operations by checking the current stream position before seeking, improving performance for sequential reads. [1] [2]

Testing Improvements:

  • Modified BufferReadAndSeekTest to wrap the memory stream with ForwardOnlyStream, better simulating streams that do not support seeking. [1] [2]

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/1160 **Author:** [@adamhathcock](https://github.com/adamhathcock) **Created:** 1/26/2026 **Status:** ✅ Merged **Merged:** 1/26/2026 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `release` ← **Head:** `adam/check-if-seek` --- ### 📝 Commits (8) - [`44e4b18`](https://github.com/adamhathcock/sharpcompress/commit/44e4b1804ec2c64f865eca8547c5c81879a82282) add check to see if we need to seek before hand - [`a82fda9`](https://github.com/adamhathcock/sharpcompress/commit/a82fda98d789a708f8429fbc6b8acbebd8ea3823) more testing and add pooling to cache - [`ddf37e8`](https://github.com/adamhathcock/sharpcompress/commit/ddf37e82c2798ed5052bd8ea5574f3319d0617fa) Initial plan - [`8c95f86`](https://github.com/adamhathcock/sharpcompress/commit/8c95f863cb8e39e1a52eebed187e1ba4f69c4042) do CanSeek first - [`875c2d7`](https://github.com/adamhathcock/sharpcompress/commit/875c2d76943dd5ca2d14c13d2b787fe1edb104b6) Fix BufferedSubStream double-dispose issue with ArrayPool - [`a0af060`](https://github.com/adamhathcock/sharpcompress/commit/a0af0604d11ab1144e4be00ec73033e66013ab16) Add disposal checks to RefillCache methods - [`56d3091`](https://github.com/adamhathcock/sharpcompress/commit/56d3091688a459229a64735b1c580e909e5ece2d) Fix condition order to check CanSeek before Position - [`7dcc13c`](https://github.com/adamhathcock/sharpcompress/commit/7dcc13c1f0d2289d6fd6f4a6af3d6c45fff8e563) Merge pull request #1161 from adamhathcock/copilot/sub-pr-1160 ### 📊 Changes **3 files changed** (+74 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/IO/BufferedSubStream.cs` (+44 -10) 📝 `src/SharpCompress/IO/SharpCompressStream.cs` (+0 -1) 📝 `tests/SharpCompress.Test/Streams/SharpCompressStreamTest.cs` (+30 -1) </details> ### 📄 Description Related to findings on https://github.com/adamhathcock/sharpcompress/issues/1105 by @julianxhokaxhiu This pull request improves memory efficiency and stream handling in `BufferedSubStream` by using pooled buffers and optimizing seek operations. It also updates the test suite to better simulate forward-only stream scenarios. **Memory Management Improvements:** * Switched `_cache` allocation in `BufferedSubStream` to use `ArrayPool<byte>.Shared.Rent` for buffer pooling, and ensured the buffer is returned to the pool in `Dispose` for reduced GC pressure. [[1]](diffhunk://#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3R2) [[2]](diffhunk://#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L31-R41) **Performance and Stream Handling Enhancements:** * Updated `RefillCache` and `RefillCacheAsync` to avoid unnecessary seek operations by checking the current stream position before seeking, improving performance for sequential reads. [[1]](diffhunk://#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3R71-R78) [[2]](diffhunk://#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3R93-R98) **Testing Improvements:** * Modified `BufferReadAndSeekTest` to wrap the memory stream with `ForwardOnlyStream`, better simulating streams that do not support seeking. [[1]](diffhunk://#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eR8) [[2]](diffhunk://#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eL67-R75) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:21:18 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1594