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

Optimize the RecyclableMemoryStream usage. #17006

Closed
wants to merge 0 commits into from

Conversation

adamradocz
Copy link
Contributor

Refer #16949

Copy link
Contributor

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());
Copy link
Member

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 ?
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants