Uh oh!
There was an error while loading. Please reload this page.
Use native bytearray truncation - #120
Conversation
lovelydinosaur
commented
Nov 24, 2020
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.
| if not out: | ||
| return None | ||
| self._start += len(out) | ||
| self._data[:count] = b"" |
There was a problem hiding this comment.
I think a del would be a little clearer but maybe it's just me. (Also below).
Uh oh!
There was an error while loading. Please reload this page.
bluetech
commented
Nov 24, 2020
With this code: size=50*2**20b=bytearray(size)
foriinrange(size):
delb[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 |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Ran Benita <ran@unusedvar.com>
njsmith
commented
Dec 23, 2020
I think this has been superseded by #115 |
pgjones
commented
Dec 26, 2020
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: