Re: [Python-Dev] [Python-checkins] cpython: asyncio: Change write buffer use to avoid O(N**2). Make write()/sendto() accept

2013/11/27 guido.van.rossum <python-checkins@python.org>:
http://hg.python.org/cpython/rev/80e0040d910c changeset: 87617:80e0040d910c user: Guido van Rossum <guido@python.org> date: Wed Nov 27 14:12:48 2013 -0800 summary: asyncio: Change write buffer use to avoid O(N**2). Make write()/sendto() accept bytearray/memoryview too. Change some asserts with proper exceptions.
Was this change discussed somewhere? Antoine told me on IRC that it was discussed on the tulip mailing list. I would be nice to mention it in the commit message (for the next change ;-).
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -340,6 +340,8 @@
max_size = 256 * 1024 # Buffer size passed to recv().
+ _buffer_factory = bytearray # Constructs initial value for self._buffer. +
Because the buffer type is now configurable, it would be nice to explain in a short comment why bytearray fits better this use case. (I like the bytearray object, so I like your whole changeset!)
@@ -762,6 +776,8 @@
class _SelectorDatagramTransport(_SelectorTransport):
+ _buffer_factory = collections.deque + def __init__(self, loop, sock, protocol, address=None, extra=None): super().__init__(loop, sock, protocol, extra) self._address = address
Why collections.deque is preferred here? Could you also please add a comment? Victor
participants (1)
-
Victor Stinner