From 1e06e0fdd8822c8f17295440f0b1d798ba3833c7 Mon Sep 17 00:00:00 2001 From: palkeo <900940+palkeo@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:31:35 +0100 Subject: [PATCH] Don't explicitly pass a default (small) receive size, let trio choose. The default size of 4 KiB is very small, and caused a lot of loops receiving buffers, that were clearly visible in benchmarks. Also, it's not needed: ` Optional; if omitted, then the stream object is free to pick a reasonable default.` By passing None, it currently means we end up in 64 KiB instead: https://github.com/python-trio/trio/blob/master/src/trio/_highlevel_socket.py#L21-L25 And it can be hoped that later this will automagically become more intelligent if they implement the TODO. --- trio_websocket/_impl.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/trio_websocket/_impl.py b/trio_websocket/_impl.py index 259f4fd..2aa0e32 100644 --- a/trio_websocket/_impl.py +++ b/trio_websocket/_impl.py @@ -38,7 +38,6 @@ CONN_TIMEOUT = 60 # default connect & disconnect timeout, in seconds MESSAGE_QUEUE_SIZE = 1 MAX_MESSAGE_SIZE = 2 ** 20 # 1 MiB -RECEIVE_BYTES = 4 * 2 ** 10 # 4 KiB logger = logging.getLogger('trio-websocket') @@ -1232,7 +1231,7 @@ async def _reader_task(self): # Get network data. try: - data = await self._stream.receive_some(RECEIVE_BYTES) + data = await self._stream.receive_some() except (trio.BrokenResourceError, trio.ClosedResourceError): await self._abort_web_socket() break