More test fixes and some perf changes#1131
Merged
adamhathcock merged 9 commits intomasterfrom Jan 15, 2026
Merged
Conversation
# Conflicts: # tests/SharpCompress.Test/GZip/GZipReaderAsyncTests.cs # tests/SharpCompress.Test/Rar/RarArchiveAsyncTests.cs # tests/SharpCompress.Test/SevenZip/SevenZipArchiveAsyncTests.cs # tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs # tests/SharpCompress.Test/Tar/TarReaderAsyncTests.cs # tests/SharpCompress.Test/Zip/Zip64AsyncTests.cs # tests/SharpCompress.Test/Zip/ZipMemoryArchiveWithCrcAsyncTests.cs
Closed
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors async ZIP archive handling and Deflate decompression to improve memory efficiency and resource management. The changes include replacing allocations with pooled buffers, updating async reading APIs for consistency, adding async disposal support to RarArchive, and fixing resource cleanup issues.
Changes:
- Refactored buffer management to use
ArrayPool<byte>andMemoryPool<byte>for reduced allocations - Updated async ZIP header reading methods to use explicit buffer arrays with offsets instead of returning new arrays
- Added
SkipAsyncmethod toAsyncBinaryReaderand replaced unnecessary buffer reads with skips - Changed Deflate decompression window from
byte[]toIMemoryOwner<byte>for pooled buffer usage
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/SharpCompress.Test/Zip/ZipMemoryArchiveWithCrcAsyncTests.cs | Wraps zipStream with AsyncOnlyStream to test async-only code paths |
| tests/SharpCompress.Test/Zip/Zip64AsyncTests.cs | Wraps file stream with AsyncOnlyStream for async testing |
| tests/SharpCompress.Test/Xz/XZStreamAsyncTests.cs | Wraps XZ streams with AsyncOnlyStream for async testing |
| tests/SharpCompress.Test/Tar/TarReaderAsyncTests.cs | Wraps file stream with AsyncOnlyStream for async testing |
| tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs | Wraps streams with AsyncOnlyStream for async testing |
| tests/SharpCompress.Test/SevenZip/SevenZipArchiveAsyncTests.cs | Switches to async archive APIs with AsyncOnlyStream wrappers |
| tests/SharpCompress.Test/Rar/RarArchiveAsyncTests.cs | Wraps file stream with AsyncOnlyStream for async testing |
| tests/SharpCompress.Test/GZip/GZipReaderAsyncTests.cs | Wraps test stream with AsyncOnlyStream for async testing |
| tests/SharpCompress.Test/BZip2/BZip2StreamAsyncTests.cs | Wraps streams with AsyncOnlyStream for async testing |
| tests/SharpCompress.Test/Arj/ArjReaderAsyncTests.cs | New async test file for ARJ reader with AsyncOnlyStream wrappers |
| tests/SharpCompress.Test/Ace/AceReaderAsyncTests.cs | New async test file for ACE reader with AsyncOnlyStream wrappers |
| src/SharpCompress/IO/SharpCompressStream.cs | Removes unused using directives |
| src/SharpCompress/IO/BufferedSubStream.cs | Changes cache allocation to use ArrayPool with proper disposal |
| src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs | Simplifies Init method by removing external window parameter |
| src/SharpCompress/Compressors/Rar/RarStream.cs | Moves readStream disposal inside disposing check |
| src/SharpCompress/Compressors/Deflate/Inflate.cs | Changes window to IMemoryOwner with proper disposal and span-based copies |
| src/SharpCompress/Common/Zip/ZipHeaderFactory.cs | Replaces unnecessary buffer read with SkipAsync |
| src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs | Uses ArrayPool for buffer allocation in header seeking with proper disposal |
| src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs | Pre-allocates byte array and uses ReadBytesAsync with explicit parameters |
| src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs | Pre-allocates byte arrays and uses ReadBytesAsync with explicit parameters |
| src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs | Pre-allocates byte arrays and uses ReadBytesAsync with explicit parameters |
| src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs | Pre-allocates byte array and uses ReadBytesAsync with explicit parameters |
| src/SharpCompress/Common/AsyncBinaryReader.cs | Changes ReadBytesAsync to write into provided buffer and adds SkipAsync method |
| src/SharpCompress/Archives/Rar/RarArchive.cs | Implements DisposeAsync with proper unpacker disposal |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Feb 11, 2026
Closed
This was referenced Feb 16, 2026
Closed
This was referenced Feb 26, 2026
Closed
This was referenced Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements and refactorings to asynchronous ZIP archive handling and Deflate decompression. The main changes include refactoring buffer management for memory efficiency, updating async reading APIs for consistency, and improving resource cleanup. These updates enhance performance, reduce allocations, and make the codebase easier to maintain.
Async ZIP reading and buffer management improvements
SeekableZipHeaderFactoryto useArrayPool<byte>for buffer allocation in async header seeking, reducing memory allocations and improving performance. Also, updated the header search logic to use spans for efficient data access. [1] [2]DirectoryEndHeader,DirectoryEntryHeader,LocalEntryHeader, andZip64DirectoryEndHeader. [1] [2] [3] [4]SkipAsyncmethod toAsyncBinaryReaderand replaced unnecessary buffer reads with skips in ZIP header parsing, improving efficiency. [1] [2]Deflate decompression memory optimization
byte[]to anIMemoryOwner<byte>fromMemoryPool<byte>, ensuring pooled buffer usage and proper disposal for reduced GC pressure and memory leaks. All array copy operations were updated to use spans. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]Resource cleanup and async disposal
DisposeAsyncinRarArchiveto support proper async resource cleanup, including disposal of unpacker resources.InflateBlocks.Free()to prevent memory leaks when decompressing data.These changes collectively improve performance, resource management, and maintainability of the archive and compression codebase.