-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-128213: fast path for bytes creation from list and tuple #132590
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
Open
eendebakpt
wants to merge
29
commits into
python:main
Choose a base branch
from
eendebakpt:fast-bytes-creation-from-list-tuple-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
6f699b5
gh-128213: fast path for bytes creation from list and tuple
blhsing 18c8e4a
coerce long to char after validation of integer in byte range
blhsing 406fbdb
📜🤖 Added by blurb_it.
blurb-it[bot] 4912a05
Update 2024-12-24-08-44-49.gh-issue-128213.Y71jDi.rst
blhsing 56f802e
updated for thread-safety, style choices, function choices and benchm…
blhsing 4e1e3e6
revert to PyLong_AsLongAndOverflow for easier overflow handling
blhsing bf96d06
fixed issue of a label at the end of a compound statment; revert to u…
blhsing f3a9423
Add FT test for bytes from list
eendebakpt 8bbc021
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt 8260c7a
Merge branch 'test_bytes_from_list' into fast-bytes-creation-from-lis…
eendebakpt bc6f8f2
refactor
eendebakpt 970c10b
refactor
eendebakpt cb664fe
refactor
eendebakpt c357217
Update Misc/NEWS.d/next/Core_and_Builtins/2024-12-24-08-44-49.gh-issu…
eendebakpt 5d53346
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt 739987e
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt 8b7c5e6
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt ab82e24
lint
eendebakpt 2e5c3c1
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt a6f74ad
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt fd28e25
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt c282610
fix merge conflicts
eendebakpt f0ab624
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt c90ae60
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt 3db5577
Update Lib/test/test_free_threading/test_bytes_object.py
eendebakpt 647975c
avoid using PyNumber_AsSsize_t
eendebakpt 85497fb
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt 6e19475
Apply suggestion from @eendebakpt
eendebakpt 67a83b9
Merge branch 'main' into fast-bytes-creation-from-list-tuple-2
eendebakpt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import unittest | ||
| from threading import Thread, Barrier | ||
| from test.support import threading_helper | ||
|
|
||
| threading_helper.requires_working_threading(module=True) | ||
|
|
||
|
|
||
| class BytesThreading(unittest.TestCase): | ||
| @threading_helper.reap_threads | ||
| def test_conversion_from_mutating_list(self): | ||
| number_of_threads = 10 | ||
| number_of_iterations = 10 | ||
| barrier = Barrier(number_of_threads) | ||
|
|
||
| x = [1, 2, 3, 4, 5] | ||
| extends = [(ii,) * (2 + ii) for ii in range(number_of_threads)] | ||
|
|
||
| def work(ii): | ||
| barrier.wait() | ||
| for _ in range(1000): | ||
| bytes(x) | ||
| x.extend(extends[ii]) | ||
| if len(x) > 10: | ||
| x[:] = [0] | ||
|
|
||
| for it in range(number_of_iterations): | ||
| worker_threads = [] | ||
| for ii in range(number_of_threads): | ||
| worker_threads.append(Thread(target=work, args=[ii])) | ||
| with threading_helper.start_threads(worker_threads): | ||
| pass | ||
|
|
||
| barrier.reset() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Core_and_Builtins/2024-12-24-08-44-49.gh-issue-128213.Y71jDi.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Speed up :class:`bytes` creation from :class:`list` and :class:`tuple` of integers by 27-31%. | ||
|
|
||
| Patch by Ben Hsing and Pieter Eendebak |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.