-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Memory Overrides to Streams #47125
Add Memory Overrides to Streams #47125
Conversation
-Implemented memory-based WriteAsync in DeflateStream.CopyToStream class. This required implementing a memory-based overload of System.IO.Inflater.SetInput(). Previously, Inflater used a GCHandle to pin the array that was passed into SetInput. I converted it to use a MemoryHandle, and changed the array-based overload of SetInput to delegate to the new Memory-based overload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this.
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs
Outdated
Show resolved
Hide resolved
In particular for any that are controversial or non-trivial, one per PR is good. For the rest, you can batch them up. |
- Memory overrides for System.Net.RequestStream - Memory overrides for System.Net.NetworkStreamWrapper
WriteAsync is implemented in terms of Write, so I went ahead and implemented Write(ReadOnlySpan<byte>). For some reason, AsSpan() isn't available in this file.
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triage: Reviewed with @adamsitnik and @jozkee and it looks good.
Suggestions have been addressed and CI is passing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you @NewellClark !
In the process of implementing Override Stream ReadAsync/WriteAsync, I ran the analyzer against dotnet/runtime and found 7 violations. This is one of them.
I've added the required memory-based overrides, and refactored it so the array-based overrides are implemented in terms of the memory-based overrides. In order to do this, I had to add an overload of
Inflater.SetBuffer
that accepts memory. Same thing here; I refactored the array-basedSetInput
to delegate to the new memory-based overload.I've also fixed
RequestStream
,ChunkedMemoryStream
, andNetworkStreamWrapper
, which were all trivial fixes.Should I do a separate PR for every violation I fix, or fix them all in one PR? Some of the fixes are non-trivial, and would require adding overloads to multiple dependencies used by the violating stream, which is why I figured a separate PR would be in order for each one.
Edit: to clarify, this is the PR I'm using for all the streams that are trivial to update. I'll be doing separate PRs for the streams that are not trivial to update.