Socket module has a socket.recv_into
method, so it can use user-defined bytebuffer
(like bytearray
) for zero-copy. But perhaps BaseEventLoop
has no method like that. Is there a way to use method like socket.recv_into
in asyncio?
The low-level socket operations defined for BaseEventLoop
require a socket.socket
object to be passed in, e.g. BaseEventLoop.sock_recv(sock, nbytes)
. So, given that you have a socket.socket
, you could call sock.recv_into()
. Whether it is a good idea to do that is another question.
You may implement own asyncio transport which utilizes .recv_into()
function but yes, for now asyncio has not a way to use .recv_into()
out-the-box.
Personally I doubt in very big speedup: when you develop with C the zero-copy is extremely important but for high-level languages like Python benefits are much lesser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With