Avoid unnecessary array allocations in ZipArchive#123836
Merged
stephentoub merged 1 commit intodotnet:mainfrom Feb 3, 2026
Merged
Avoid unnecessary array allocations in ZipArchive#123836stephentoub merged 1 commit intodotnet:mainfrom
stephentoub merged 1 commit intodotnet:mainfrom
Conversation
…y{Async}
And simplify a few open-coded loops into span operations.
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression |
Contributor
There was a problem hiding this comment.
Pull request overview
Reduce GC pressure and simplify inner-loop code paths in System.IO.Compression by reusing buffers from ArrayPool<byte> and replacing manual loops with span operations.
Changes:
- Replace allocating range operations / intermediate arrays with pooled buffers when reading the Zip central directory (sync + async).
- Fix an allocation-heavy path in
ZipCentralDirectoryFileHeader.TryReadBlockAsyncby collating into a pooledMemory<byte>rather than creating a new array. - Simplify repeated writes in
InflaterManaged.DecodeDynamicBlockHeaderusingSpan.Fill/Span.Clear.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.Async.cs | Uses a pooled buffer to collate dynamic header data without extra array allocations. |
| src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.cs | Central directory read buffer is rented from ArrayPool<byte> instead of allocating a new array per read. |
| src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.Async.cs | Async central directory parsing avoids range-operator array allocations by using ReadOnlyMemory<byte> slices over pooled buffers. |
| src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/InflaterManaged.cs | Replaces small write loops with span-based fill/clear operations. |
This was referenced Jan 31, 2026
alinpahontu2912
approved these changes
Feb 3, 2026
Member
alinpahontu2912
left a comment
There was a problem hiding this comment.
Lgtm, nice improvements
lewing
pushed a commit
to lewing/runtime
that referenced
this pull request
Feb 9, 2026
And simplify a few open-coded loops into span operations.
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.
And simplify a few open-coded loops into span operations.