eandersson / amqpstorm

Thread-safe Python RabbitMQ Client & Management library
https://www.amqpstorm.io/
MIT License
186 stars 36 forks source link

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

Open visobet opened 7 months ago

visobet commented 7 months ago

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.

eandersson commented 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.