Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Override WriteAsync on the DefaultPipeWriter #35484

Merged
merged 2 commits into from
Feb 21, 2019
Merged

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Feb 21, 2019

  • 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
@davidfowl davidfowl requested review from pakrym and jkotalik February 21, 2019 09:26
Copy link
Member

@benaadams benaadams left a 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;
Copy link

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

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

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

Copy link
Member Author

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

Copy link
Member

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)

@davidfowl davidfowl merged commit a0bbeb7 into master Feb 21, 2019
@stephentoub stephentoub deleted the davidfowl/write-async branch February 22, 2019 03:53
@karelz karelz added this to the 3.0 milestone Mar 18, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
- 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
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants