Repository navigation
gh-129813: Use PyBytesWriter in binascii - #162259
Conversation
|
cc @vstinner Another found after checking the |
vstinner
left a comment
There was a problem hiding this comment.
LGTM. Nice usage of PyBytesWriter_FinishWithSize() to truncate the overallocated bytes object.
The old code initialized bytes to zero (PyMem_Calloc()) which is not needed and had to copy bytes (PyMem => PyBytes). I expect that the new code has less work to do and so can be a little bit faster.
Reducing the peak memory footprint by a factor of 2 is great! Some operations are also up to 1.08x faster according to your benchmark.
|
@vstinner Thank you :) for taking a look and merging. Truth to be told, at some point I realized it's better to underhype any |
Yeah, that's why I added "skip news", I'm sure that it's worth it document such optimization. While the lower peak memory usage is great, the CPU time is faster but no so much faster. |
Use
PyBytesWriterinbinascii.b2a_qp()anda2b_qp(), spares a temp buffer and a copy. This extends #138825.This is mostly a simplification but there's memory improvement:
And pyperf improvement:
(PGO+LTO, macOS arm64)
memory measure
pyperf benchmark