Open visobet opened 7 months ago
Hey!
This sounds like a great idea for a PR. I think the only caveat is that if this does not work on Python 2.7, this needs to go on the main
branch, and if it works on both Python 2.7 and 3.X it should go on the 2.x
branch.
Hi.
I noticed in channel.py, that
self._inbound
is a list andbuild_incoming_message
doespop(0)
which has an O(n) performance.collections.deque
would offer a O(1)popleft
method.I guess usually
self._inbound
should be rather short, so it would not make a difference. But I noticed that sometimes, if we are already slow with consuming/ processing messages and self_incoming fills up, then thispop(0)
makes us even slower and shows up in the profiler.According to the documentation, appending and popping to/from the end of a deque is thread safe (https://docs.python.org/3/library/collections.html#deque-objects)
Is there any reason not to switch to a deque? Anything I might not have thought of?
If using a deque is fine, then I could create a PR.