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

Speed up bytes creation from list and tuple #128213

Open
blhsing opened this issue Dec 24, 2024 · 2 comments
Open

Speed up bytes creation from list and tuple #128213

blhsing opened this issue Dec 24, 2024 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage type-feature A feature request or enhancement

Comments

@blhsing
Copy link
Contributor

blhsing commented Dec 24, 2024

Feature or enhancement

Proposal:

The performance of bytes creation from list and tuple can benefit from the same fast path using PySequence_Fast_ITEMS done for bytearray in gh-91149.

I have a PR ready.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@blhsing blhsing added the type-feature A feature request or enhancement label Dec 24, 2024
blhsing added a commit to blhsing/cpython that referenced this issue Dec 24, 2024
@eendebakpt eendebakpt added the performance Performance or resource usage label Dec 24, 2024
@picnixz picnixz added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Dec 24, 2024
@serhiy-storchaka
Copy link
Member

How much does it benefit? Please show some microbenchmark results.

@blhsing
Copy link
Contributor Author

blhsing commented Dec 25, 2024

How much does it benefit? Please show some microbenchmark results.

I just finished updating my benchmark results in the PR, but I'll cross-post them here:

Benchmark using python -m timeit -n 100 -s 'a = __import__("random").choices(range(256), k=1000000)' 'bytes(a)' showing a ~31% reduction in time consumed:

100 loops, best of 5: 3.21 msec per loop # current
100 loops, best of 5: 2.23 msec per loop # this PR

With k=10000, a ~30% time reduction:

100 loops, best of 5: 31.7 usec per loop # current
100 loops, best of 5: 22.3 usec per loop # this PR

With k=100, a ~27% time reduction:

100 loops, best of 5: 410 nsec per loop # current
100 loops, best of 5: 299 nsec per loop # this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants