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

Avoid buffering the content before streaming to the response body #2792

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

gfoidl
Copy link
Contributor

@gfoidl gfoidl commented Nov 22, 2023

Addressed the point outlined in #2408 (comment) and contributes to #2791 (but does not fix that issue1)

For array streaming the whole content was buffered in a memory stream, then copied to the ASP.NET Core's response stream.
This has some downsides:

  • the content-length isn't needed, ASP.NET Core will produce a chunked output, which can be read by any client
  • it needs copying to the memory stream to the response -- which can be resource intensive for large data
  • for large data it's possible that the memory stream gets bigger than 85.000 bytes, so it's above the large object heap (LOH) threshold of the GC, thus that object will live until a Gen-2 collection happens

These points can be avoided by writing to the response stream directly.

Footnotes

  1. I'll try to address the pooling, etc. point later, as that's not so straight forward.

Copy link
Collaborator

@oskardudycz oskardudycz left a comment

Choose a reason for hiding this comment

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

Thanks, that's a nice improvement!

@oskardudycz oskardudycz merged commit b5bfaf6 into JasperFx:master Nov 23, 2023
13 checks passed
@gfoidl gfoidl deleted the aspnet-streaming branch November 23, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants