-
Notifications
You must be signed in to change notification settings - Fork 10k
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 during input formatting for longer than necessary #9806
Conversation
src/Mvc/Mvc.Formatters.Xml/test/XmlDataContractSerializerInputFormatterTest.cs
Show resolved
Hide resolved
Exception exception = null; | ||
object model; | ||
|
||
using (var streamReader = context.ReaderFactory(readStream, encoding)) |
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.
Just moved the ErrorHandler
out of the try-catch block since it doesn't need to be there. Besides disposing the FileBufferingReadStream
, the rest of this is unchanged.
src/Mvc/Mvc.Formatters.Xml/src/XmlDataContractSerializerInputFormatter.cs
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.
What about the XML perf?
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.
Any particular thing you wanted me to look at @pranavkm?
src/Mvc/Mvc.Formatters.Xml/src/XmlDataContractSerializerInputFormatter.cs
Show resolved
Hide resolved
So what the impact of this if you wanted to rewind and reread the stream? Would you see a non-seekable stream that's at the end? What's required if a user wants to enforce buffering (and allow rewinding)? I'm asking because I'm sure someone has done this, and we're changing the default. |
EnableRewind uses FileBufferingReadStream which is not disposed until the response is completed. This results in holding on to internal buffers for significantly longer than necessary.Changing it to return the buffers immediately improved the allocations and throughput.
You can explicitly call |
f766c3e
to
a55134c
Compare
Co-Authored-By: pranavkm <[email protected]>
🆙 📅 |
EnableRewind uses FileBufferingReadStream which is not disposed until the response is completed.
This results in holding on to internal buffers for significantly longer than necessary. Changing it
to return the buffers immediately improved the allocations and throughput.