-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Override WriteAsync on the DefaultPipeWriter #35484
Conversation
davidfowl
commented
Feb 21, 2019
•
edited
Loading
edited
- Today we're using an extension method on IBufferWrite to implement copying the input buffer to the underlying PipeWriter. Luckily this method is virtual so we can optimize using the Pipe's internal structures directly rather than going through GetMemory and Advance
- Today we're using an extension method on IBufferWrite<T> to implement copying the input buffer to the underlying PipeWriter. Luckily this method is virtual so we can optimize using the Pipe's internal structures directly rather than going through GetMemory and Advance
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.
Nice!
} | ||
|
||
// We filled the segment | ||
_writingHead.End += writable; |
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.
On a related note, we might want to pull more stuff from under the lock in AllocateWriteHeadSynchronized considering _writingHead doesn't need to be thread-safe.
|
||
// This is optimized to use pooled memory. That's why we pass 0 instead of | ||
// source.Length | ||
BufferSegment newSegment = AllocateSegment(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.
Not a fan of having linked list building code in multiple places.
// source.Length | ||
BufferSegment newSegment = AllocateSegment(0); | ||
|
||
_writingHead.SetNext(newSegment); |
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.
Does .SetNext
need to be done under lock, or is it ok as writing is active and is purely in the uncommited portion?
If not then (not for this PR); _operationState.BeginWrite()
could be made lock-free * and only the portion of AllocateWriteHeadSynchronized
that's touching the _readHead
and _readTail
would need the lock?
* Avoiding race with _operationState.IsWritingActive
in AdvanceReader would be the trickier bit
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.
Pretty sure it’s ok. Those are good follow up items
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.
Yea me too; mostly a check and follow up on @pakrym's suggestion #35484 (comment)
- Today we're using an extension method on IBufferWrite<T> to implement copying the input buffer to the underlying PipeWriter. Luckily this method is virtual so we can optimize using the Pipe's internal structures directly rather than going through GetMemory and Advance Commit migrated from dotnet/corefx@a0bbeb7