You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. add `tp_new` to guarantee `ob_bytes_head` is always set, often to the empty
bytes singleton.
2. `ob_alloc` information is now redundant, added assertion to validate that,
would it make sense to deprecate?
3. There's a lot of `bytearray` code very similar to `bytes` code, more could
likely be just proxied to the `bytes` now. Here just focusing on the swap as
that enables optimizations.
4. If `bytearray` is passed a single-reference bytes it could potentially take
"ownership" of it without copying the bytes, for now not implemented.
This enables adding `bytearray._detach()` which I plan to do in a separate PR.
```bash
./python -m test -M8g -uall test_largefile -m test.test_largefile.CLargeFileTest.test_large_read
./python -m test -M8g -uall test_largefile -m test.test_largefile.PyLargeFileTest.test_large_read
```
On my machine (AMD 64 bit Linux, Optimized build):
`_io` takes: ~0.791s and uses ~2GB of RAM
`_pyio` current: ~1.073s and uses ~4GB of RAM
`_pyio` w/ bytearray._detach: ~0.887s and uses ~2GB of RAM
Perf checking no major swings in an optimized build:
`./python -E -bb -Wd -m test -uall -M32G test_bytes test_capi.test_bytearray -vvv`
before: ~1.4s
after: ~1.5s
Previous discussion: https://discuss.python.org/t/add-zero-copy-conversion-of-bytearray-to-bytes-by-providing-bytes/79164
0 commit comments