Skip to content

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

Merged
asvetlov merged 6 commits into
python:mainfrom
kumaraditya303:bytearray
Mar 15, 2022
Merged

bpo-46993: Speed up bytearray creation from list and tuple#31834
asvetlov merged 6 commits into
python:mainfrom
kumaraditya303:bytearray

Conversation

@kumaraditya303

@kumaraditya303kumaraditya303 commented Mar 12, 2022

Copy link
Copy Markdown
Contributor

Speeds up bytearray creation from list and tuples.

Benchmark:

importpyperfrunner=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

@kumaraditya303kumaraditya303 changed the title optimize bytearray for list and tuplebpo-46993: Speed up bytearray creation from list and tupleMar 12, 2022
@kumaraditya303
kumaraditya303 marked this pull request as ready for review March 12, 2022 09:41
Comment threadObjects/bytearrayobject.c
Comment threadObjects/bytearrayobject.c
@kumaraditya303
kumaraditya303 marked this pull request as draft March 13, 2022 06:30
@kumaraditya303
kumaraditya303 marked this pull request as ready for review March 13, 2022 07:28

@gvanrossumgvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@asvetlov
asvetlov merged commit 6dfe09f into python:mainMar 15, 2022
@kumaraditya303
kumaraditya303 deleted the bytearray branch March 15, 2022 13:28
@kumaraditya303

Copy link
Copy Markdown
ContributorAuthor

Thanks @asvetlov and @gvanrossum

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@kumaraditya303@asvetlov@JelleZijlstra@gvanrossum@peendebak@the-knights-who-say-ni@bedevere-bot