Skip to content
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

Using stackalloc instead of new byte[x] on Streams #88303

Merged
merged 26 commits into from
Aug 11, 2023

Conversation

Poppyto
Copy link
Contributor

@Poppyto Poppyto commented Jul 2, 2023

Replace new[] allocations with stackalloc for one byte array in different Stream classes.
I don't think there will be a big performance change at the CPU level but it will always be a gain on the garbage collector

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 2, 2023
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 2, 2023
@Poppyto Poppyto changed the title Using stackalloc instead of new byte[x] Using stackalloc instead of new byte[x] on Streams Jul 2, 2023
@filipnavara filipnavara added area-System.IO and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 2, 2023
@ghost
Copy link

ghost commented Jul 2, 2023

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Replace new[] allocations with stackalloc for one byte array in different Stream classes.
I don't think there will be a big performance change at the CPU level but it will always be a gain on the garbage collector

Author: Poppyto
Assignees: -
Labels:

area-System.IO, community-contribution

Milestone: -

@stephentoub
Copy link
Member

Thanks, but these are all async methods accepting Memory, not Span. You can't pass a stackalloc'd span to them. This will not compile.

@Poppyto
Copy link
Contributor Author

Poppyto commented Jul 2, 2023

Thanks, but these are all async methods accepting Memory, not Span. You can't pass a stackalloc'd span to them. This will not compile.

How could I missed that ! Fixed :) - rollback for DecompressionHandler - Other changes seem fine.

Copy link
Contributor

@teo-tsirpanis teo-tsirpanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the span constructors introduced in .NET 7 instead of stackalloc.

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 5, 2023
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 5, 2023
Poppyto and others added 2 commits July 5, 2023 13:19
…tem/Runtime/Serialization/Json/JsonEncodingStreamWrapper.cs


replace Span by ReadOnlySpan

Co-authored-by: Michał Petryka <35800402+MichalPetryka@users.noreply.github.com>
Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my remaining comments, LGTM.

Poppyto and others added 2 commits August 9, 2023 18:37
…tem/Runtime/Serialization/Json/JsonEncodingStreamWrapper.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
…tem/Runtime/Serialization/Json/JsonEncodingStreamWrapper.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
@StephenMolloy StephenMolloy merged commit d87964d into dotnet:main Aug 11, 2023
98 of 99 checks passed
@ghost ghost locked as resolved and limited conversation to collaborators Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Serialization community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants