Use native bytearray truncation#120
Use native bytearray truncation#120lovelydinosaur wants to merge 6 commits intopython-hyper:masterfrom
Conversation
|
We also ought to follow up on the action in the comment "make sure PyPy also has the optimization", but I'm not sure where to start with that. |
| # bytearray is amortized O(n), thanks to some excellent work by Antoine | ||
| # Martin: | ||
| # | ||
| # https://bugs.python.org/issue19087 |
There was a problem hiding this comment.
I think it'd be helpful to keep the paragraph above.
There was a problem hiding this comment.
Fair point, yes. I've addressed it as an inline comment.
h11/_receivebuffer.py
Outdated
There was a problem hiding this comment.
I think a del would be a little clearer but maybe it's just me. (Also below).
There was a problem hiding this comment.
Agreed, yup!
With this code: size = 50 * 2**20
b = bytearray(size)
for i in range(size):
del b[0]Results: So it's either that pypy has this optimization, or it's doing some magic JIT handling of this specific code. I tried some tricks to foil any such optimization and it seems legit. If we're willing to have a timing-based unit test for this, a |
Co-authored-by: Ran Benita <ran@unusedvar.com>
|
I think this has been superseded by #115 |
|
Agree with #115 superseding this. (Please reopen if not). |
Switching from
.compress()to using native buffer truncation.I figure despite some related work on #115 it's worth looking at this PR in isolation.
We probably want this to be blocked on #116.
Benchmarking on Python 3.7...
Before:
After: