You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Speed up bytes creation from list and tuple #128213
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
Activity
pythongh-128213: fast path for bytes creation from list and tuple
serhiy-storchaka commentedon Dec 25, 2024
How much does it benefit? Please show some microbenchmark results.
blhsing commentedon Dec 25, 2024
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:With
k=10000, a ~30% time reduction:With
k=100, a ~27% time reduction:sergey-miryanov commentedon Dec 1, 2025
@blhsing @eendebakpt Is there anything else we still need to do?
eendebakpt commentedon Dec 1, 2025
Yes. There is a free-threading bug and potentially a performance gain. The PR #132590 is ready for review.
gh-128213: fast path for bytes creation from list and tuple (#132590)
pythongh-128213: fast path for bytes creation from list and tuple (py…
pythongh-128213: fast path for bytes creation from list and tuple (py…