-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Optimize the RecyclableMemoryStream usage. #17006
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting your first pull request, awesome! 🚀 If you haven't already, please take a moment to review our contribution guide. This guide provides helpful information to ensure your contribution aligns with our standards. A core team member will review your pull request. |
@@ -54,7 +54,7 @@ public async Task<IActionResult> ServiceEndpoint([ModelBinder(BinderType = typeo | |||
result.Save(w); | |||
} | |||
|
|||
var content = Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Length); | |||
var content = Encoding.UTF8.GetString(stream.GetReadOnlySequence()); |
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.
Didn't know about these, apparently there are a few in EncodingExtensions
. We should check if there aren't other places where we could use these.
@@ -50,7 +50,12 @@ static CommonGeneratorMethods() | |||
using var uncompressedStream = MemoryStreamFactory.GetStream((int)compressedStream.Length); | |||
gZip.CopyTo(uncompressedStream); | |||
|
|||
return Convert.ToBase64String(uncompressedStream.GetBuffer(), 0, (int)uncompressedStream.Length); | |||
var readOnlySequence = uncompressedStream.GetReadOnlySequence(); | |||
var base64String = readOnlySequence.IsSingleSegment ? |
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.
I don't think that is necessary because the stream will do it already: https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream/blob/master/src/RecyclableMemoryStream.cs#L508
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.
Yes, you're right. It would only make sense if ReadOnlySequence
could be used instead.
Refer #16949