Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit d804f21

Browse files
committed
Use deques for frame queues.
Python lists make bad queues. Rather than being linked-lists they're actually fancy arrays. This means popping from the left (which frame queues do) requires that the array be resized and potentially reallocated. We should avoid some of that memory churn.
1 parent 2da7440 commit d804f21

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

hyper/http20/stream.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ContinuationFrame,
1919
)
2020
from .response import HTTP20Response
21+
import collections
2122

2223

2324
# Define a set of states for a HTTP/2.0 stream.
@@ -52,7 +53,7 @@ def __init__(self,
5253
self.stream_id = stream_id
5354
self.state = STATE_IDLE
5455
self.headers = []
55-
self._queued_frames = []
56+
self._queued_frames = collections.deque()
5657

5758
# There are two flow control windows: one for data we're sending,
5859
# one for data being sent to us.
@@ -118,7 +119,7 @@ def listlen(list):
118119
# Begin by processing frames off the queue.
119120
while amt is None or listlen(data) < amt:
120121
try:
121-
frame = self._queued_frames.pop(0)
122+
frame = self._queued_frames.popleft()
122123
except IndexError:
123124
# No frames on the queue. Try to read one and try again.
124125
self._recv_cb()
@@ -204,7 +205,7 @@ def getresponse(self):
204205
# connection if necessary.
205206
while True:
206207
try:
207-
frame = self._queued_frames.pop(0)
208+
frame = self._queued_frames.popleft()
208209
except IndexError:
209210
self._recv_cb()
210211
continue

0 commit comments

Comments
 (0)