You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently if you want to copy a buffered reader into a writer the easiest way is reader.copy_into(writer), this won't use the buffered readers buffer and will instead use an internal buffer in the CopyInto future.
This can be ok for some buffered readers like the provided BufReader as they will bypass their internal buffer when doing large reads (although this assumes that CopyInto will use at least the same buffersize as the BufReader), but for other buffered readers like an IntoAsyncRead wrapping a Stream<Item = Vec<u8>> there will be definite performance loss from extra copying required.
We could provide a similar function on AsyncBufRead and keep the existing one, but I think it would be better to just move it to AsyncBufRead and require users to wrap their reader in a BufReader if they want to copy from a non-buffered reader (which will also allow them to choose the buffer size for their application if they want).
The text was updated successfully, but these errors were encountered:
@cramertj how do you feel about adding an additional AsyncBufReadExt::copy_buf_into method to allow users to avoid the additional copying?
Eventually AsyncReadExt::copy_into might be able to specialize based on Self: AsyncBufRead, but I think it makes sense to be able to directly control the buffer size/guarantee you're using the buffered method when needed.
Currently if you want to copy a buffered reader into a writer the easiest way is
reader.copy_into(writer)
, this won't use the buffered readers buffer and will instead use an internal buffer in theCopyInto
future.This can be ok for some buffered readers like the provided
BufReader
as they will bypass their internal buffer when doing large reads (although this assumes thatCopyInto
will use at least the same buffersize as theBufReader
), but for other buffered readers like anIntoAsyncRead
wrapping aStream<Item = Vec<u8>>
there will be definite performance loss from extra copying required.We could provide a similar function on
AsyncBufRead
and keep the existing one, but I think it would be better to just move it toAsyncBufRead
and require users to wrap their reader in aBufReader
if they want to copy from a non-buffered reader (which will also allow them to choose the buffer size for their application if they want).The text was updated successfully, but these errors were encountered: