Skip to content

gh-128213: fast path for bytes creation from list and tuple - #132590

Merged
kumaraditya303 merged 38 commits into
python:mainfrom
eendebakpt:fast-bytes-creation-from-list-tuple-2
Sep 12, 2026
Merged

kumaraditya303 merged 38 commits into
python:mainfrom
eendebakpt:fast-bytes-creation-from-list-tuple-2

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Apr 16, 2025 •

Copy link
Copy Markdown
Contributor

Continuation of #128214. This PR

  • Improves performance of bytes creation from a list or tuple. On the FT build performance on a list of tuple of size 1000 the method is about 2 to 3x times faster (mainly because the old code uses per element atomic operations via _PyList_GetItemRef).
  • Fixes a free-threading bug (update: the issue has been resolved on main while the PR was open, the test is still added)
  • Reduces some duplicated code between list and tuple handling

Comment thread Objects/bytesobject.c Resolved
@eendebakpt
eendebakpt marked this pull request as draft April 16, 2025 12:41
@eendebakpt
eendebakpt marked this pull request as ready for review April 16, 2025 14:09
@eendebakpt

Copy link
Copy Markdown
Contributor Author

@markshannon Would you be able to continue reviewing this one?

@eendebakpt

Copy link
Copy Markdown
Contributor Author

@colesbury Would you be able to review?

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 9, 2026
eendebakpt and others added 3 commits September 9, 2026 16:03
Use the PyDict_GetItemRef()-style tri-state contract instead: return 1
on success with *result set, 0 to fall back to the slow path, and -1 on
error with an exception set.

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
…rom-list-tuple-2

# Conflicts:
#	Objects/bytesobject.c
Comment thread Objects/bytesobject.c Resolved
Co-authored-by: Kumar Aditya <[email protected]>
@kumaraditya303
kumaraditya303 merged commit 4702980 into python:main Sep 12, 2026
58 checks passed
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
johnslavik pushed a commit to johnslavik/cpython that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time. topic-free-threading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants