-
Notifications
You must be signed in to change notification settings - Fork 10.4k
HttpRequestStreamReader overrides for Read Span, ReadAsync Memory, ReadLine and ReadLineAsync #18802
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
HttpRequestStreamReader overrides for Read Span, ReadAsync Memory, ReadLine and ReadLineAsync #18802
Conversation
Hi @jkotalik , It adds complexity to this class but given the performance boost should be worth it. I've also upped the test coverage to increase confidence on this addition. I'm not really happy about the input/output parameters of the step method, especially the mixing of a return struct and ref parameters, but after some experiments this looked like the more readable version. Any suggestion? About the benchmark,
|
Hi @jkotalik , |
Hello! please let me know if I need to rebase this! thanks |
_charBufferIndex += charsRemaining; | ||
|
||
charsRead += charsRemaining; | ||
count -= charsRemaining; | ||
|
||
if (count > 0) |
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.
Why do we need to check count > 0
?
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.
we don't
|
||
_charBufferIndex += n; | ||
if (charsAvailable < count) |
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.
Why can't this be the same check done in Read with:
if (count > 0)
{
buffer = buffer.Slice(charsRemaining, count);
}
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.
aligned to Read
. Also renamed charsAvailable
to charsRemaining
for simmetry.
return stepResult.Result ?? sb?.ToString(); | ||
} | ||
|
||
continue; |
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.
nit: no need for continue.
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.
😅 oops!
{ | ||
if (consumeLineFeed) | ||
{ | ||
if (_charBuffer[_charBufferIndex] == '\n') |
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.
nit: I'd make \r and \n constants.
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.
is it ok local to the method?
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.
With some minor nits, LGTM.
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.
Thanks for the review. I've updated it to address the feedback.
_charBufferIndex += charsRemaining; | ||
|
||
charsRead += charsRemaining; | ||
count -= charsRemaining; | ||
|
||
if (count > 0) |
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.
we don't
|
||
_charBufferIndex += n; | ||
if (charsAvailable < count) |
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.
aligned to Read
. Also renamed charsAvailable
to charsRemaining
for simmetry.
return stepResult.Result ?? sb?.ToString(); | ||
} | ||
|
||
continue; |
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.
😅 oops!
{ | ||
if (consumeLineFeed) | ||
{ | ||
if (_charBuffer[_charBufferIndex] == '\n') |
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.
is it ok local to the method?
Compiler error? |
23b6f74
to
327aa1f
Compare
Sorry @Tratcher , I didn't realize that the CI build the outcome of the merge on master and I guess the benchmark library has been updated on master. Thank you, |
Thanks! |
This is the corresponding change of #18451 (HttpResponseStreamWriter)
Currently the
HttpRequestStreamReader
relies on the base class implementation which cause a sync over async call.This include a change on the sync implementation of
Read(char[] buffer, int index, int count)
to reuse theSpan<char>
implementation and consolidate the code, but I'm not sure if there are performance concern with this change.Related to #2895 and #16740