-
Notifications
You must be signed in to change notification settings - Fork 77
Use native bytearray truncation #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use native bytearray truncation #120
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be helpful to keep the paragraph above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, yes. I've addressed it as an inline comment.
h11/_receivebuffer.py
Outdated
if not out: | ||
return None | ||
self._start += len(out) | ||
self._data[:count] = b"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a del
would be a little clearer but maybe it's just me. (Also below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: