amqpstorm icon indicating copy to clipboard operation
amqpstorm copied to clipboard

channel.py Could self._inbound be a deque instead of a list

Open visobet opened this issue 1 year ago • 1 comments

Hi.

I noticed in channel.py, that self._inbound is a list and build_incoming_message does pop(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 this pop(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.

visobet avatar Jan 22 '24 11:01 visobet

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.

eandersson avatar Jan 26 '24 03:01 eandersson