This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improve performance of bytes_repeat
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, pieter.eendebak, python-dev
Priority: normal Keywords: patch

Created on 2022-03-13 19:01 by pieter.eendebak, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31856 merged python-dev, 2022-03-13 19:07
Messages (3)
msg415077 - (view) Author: Pieter Eendebak (pieter.eendebak) * Date: 2022-03-13 19:01
The bytearray_repeat and bytearray_irepeat are inefficient for small arrays and a high number of repeats.
This can be improved by using the same approach is in the corresponding bytes_repeat method.

Microbenchmark:

python -m pyperf timeit "b=bytearray([1,2,])*100" 

Mean +- std dev: [base100] 479 ns +- 29 ns -> [patch100] 274 ns +- 18 ns: 1.75x faster

python -m pyperf timeit "b=bytearray([1,2,])*1000"

Mean +- std dev: [base1000] 2.58 us +- 0.18 us -> [patch1000] 399 ns +- 26 ns: 6.46x faster
msg415457 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-03-17 23:10
New changeset ac8308d3eaf2526318c1bbf13d4a214fd24605d2 by Pieter Eendebak in branch 'main':
bpo-47005: Improve performance of bytearray_repeat and bytearray_irepeat (GH-31856)
https://github.com/python/cpython/commit/ac8308d3eaf2526318c1bbf13d4a214fd24605d2
msg415458 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-03-17 23:11
Thanks for the contribution -- that's a really nice speedup.
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91161
2022-03-17 23:11:56Dennis Sweeneysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-03-17 23:11:46Dennis Sweeneysetmessages: + msg415458
2022-03-17 23:10:55Dennis Sweeneysetnosy: + Dennis Sweeney
messages: + msg415457
2022-03-13 19:07:01python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request29954
stage: patch review
2022-03-13 19:01:26pieter.eendebakcreate