Repository navigation
Reuse plain frame bodies during serialization - #177
notatallshaw wants to merge 2 commits into
Conversation
| if isinstance(self.data, memoryview): | ||
| self.data = self.data.tobytes() | ||
|
|
||
| if type(self.data) is bytes and type(padding_data) is bytes and not padding_data and not padding: |
There was a problem hiding this comment.
please use isinstance() as the canonical way of checking a if the object is of a certain instance of a class.
There was a problem hiding this comment.
This is intentional, this a fast-path guard. because we know exactly the behavior of the bytes object.
A subclass of bytes could override __len__ and cause writing the wrong payload length. But with this guard they fall through to the join.
|
Could the condition check be simplified to only look at |
|
Pinging @fhgffy from #174 to bring both conversations together.
Since the same logic applies to 3 frames: HEADERS, DATA, PUSH_PROMISE, we should bring most of the logic into the |
Added a commit that simplifies the check to look at the bytes each field adds. Can't take that approach because with PADDED set and pad_length set to zero, b"abc" has to go out as b"\x00abc", otherwise the receiver reads |
Unpadded DATA and HEADERS serialization copies the complete body while joining it with empty fields, even though no framing data is added.
Avoid that copy for exact bytes bodies. Replaying the 40 affected frame operations from a local HTTP/2 capture is about 7% faster (99% interval: about 3% to 9%).