From 3cb5ec11e8fa510a4ab7c0a313b9a178b8c7b9ad Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 1 Nov 2024 06:43:10 -0500 Subject: [PATCH] Implement zerocopy writes With Python 3.12+ and later transport.writelines is implemented as `sendmsg(..., IOV_MAX)` which allows us to avoid joining the bytes and sending them in one go --- aioesphomeapi/_frame_helper/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aioesphomeapi/_frame_helper/base.py b/aioesphomeapi/_frame_helper/base.py index e24f1e70..3997c24a 100644 --- a/aioesphomeapi/_frame_helper/base.py +++ b/aioesphomeapi/_frame_helper/base.py @@ -52,9 +52,9 @@ def __init__( self._loop = loop self._connection = connection self._transport: asyncio.Transport | None = None - self._writelines: None | (Callable[[bytes | bytearray | memoryview], None]) = ( - None - ) + self._writelines: ( + None | (Callable[[Iterable[bytes | bytearray | memoryview[int]]], None]) + ) = None self.ready_future = self._loop.create_future() self._buffer: bytes | None = None self._buffer_len = 0