Skip to content
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

bpo-46993: Speed up bytearray creation from list and tuple #31834

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Mar 12, 2022

Speeds up bytearray creation from list and tuples.

Benchmark:

import pyperf

runner = pyperf.Runner()
runner.timeit(name="bench bytearray",
              stmt="bytearray([42]*10000)",)

Result:

Mean +- std dev: [base] 74.8 us +- 5.5 us -> [patch] 53.2 us +- 3.3 us: 1.41x faster

https://bugs.python.org/issue46993

@kumaraditya303 kumaraditya303 changed the title optimize bytearray for list and tuple bpo-46993: Speed up bytearray creation from list and tuple Mar 12, 2022
@kumaraditya303 kumaraditya303 marked this pull request as ready for review Mar 12, 2022
Objects/bytearrayobject.c Outdated Show resolved Hide resolved
@kumaraditya303 kumaraditya303 requested a review from gvanrossum Mar 13, 2022
@kumaraditya303 kumaraditya303 marked this pull request as draft Mar 13, 2022
@kumaraditya303 kumaraditya303 marked this pull request as ready for review Mar 13, 2022
Copy link
Member

@gvanrossum gvanrossum left a comment

Yes, much better.

I suppose there's a way to observe the new behavior, if the jump to the slow path must be taken: the offending subtype-of-long-instance will see that its __index__ method is called twice. But I see no reason this would matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants