Skip to content

proposal: io: add WriterTo to PipeReader and ReaderFrom to PipeWriter #54877

@Jorropo

Description

@Jorropo

There is opportunities to skip synchronization events, allocations and maybe even do some zero copies (if WriteTo and ReadFrom are called concurrently).

If ReadFrom is called this would allow Read to acquire a reference to the Reader passed in and pass the buffer slice to the reader directly (skipping a possible allocation that would have been required to copy data from Reader to PipeWriter).
If WriteTo is called this would allow Write to acquire a reference to the Writer passed in and pass the buffer slice to the reader directly (skipping a possible allocation that would have required to copy data from PipeReader to Writer).
If ReadFrom and WriteTo are called this would allow to call io.Copy (or equivalent reusing a buffer) to maybe do a zero copy between the Writer and Reader.

The implementation would need to account for the fact that ReadFrom can be called multiple times and WriteTo need to waits until the pipe is closed, but nothing that cannot be done.

The extra channels required to pass the Writer and Reader around might be much in term of extra allocations, I guess a sync based implementation (instead of channels) would be better (as it would just embed all synchronization primitives into the pipe struct).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions