#5628 enhancement new
Use collections.deque for the data structure in DeferredQueue
|Reported by:||Dev0n||Owned by:|
This is really micro-optimising as I was assured by a few of the twisted devs in #twisted that DeferredQueue is hardly ever a bottleneck.
Testing list vs deque:
python -mtimeit -s'q=range(10)' 'q.append(11); q.pop(0)' 1000000 loops, best of 3: 0.776 usec per loop python -mtimeit -s'import collections; q=collections.deque(range(10))' 'q.append(11); q.popleft()' 1000000 loops, best of 3: 0.416 usec per loop
As you can see, the data set doesn't necessarily have to be big to have a _slight_ effect on performance.
I've attached a benchmarking script that I used to compare before and after the data structure change and all tests passed.
trial test_defer.py ... testQueue ... [OK] test_cancelQueueAfterGet ... [OK] test_cancelQueueAfterSynchronousGet ... [OK] ...