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

gh-128213: fast path for bytes creation from list and tuple#132590
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 Misc/NEWS.d/next/Core_and_Builtins/2024-12-24-08-44-49.gh-issue-128213.Y71jDi.rst Outdated
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2024-12-24-08-44-49.gh-issue-128213.Y71jDi.rst Outdated
Comment thread Objects/bytesobject.c Outdated
@eendebakpt
eendebakpt marked this pull request as draft April 16, 2025 12:41
eendebakpt and others added 4 commits April 16, 2025 14:58
…e-128213.Y71jDi.rst

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@eendebakpt
eendebakpt marked this pull request as ready for review April 16, 2025 14:09
Comment thread Lib/test/test_free_threading/test_bytes_object.py Outdated
@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 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…rom-list-tuple-2

# Conflicts:
#	Objects/bytesobject.c
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2024-12-24-08-44-49.gh-issue-128213.Y71jDi.rst Outdated
Comment thread Objects/bytesobject.c Outdated
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2024-12-24-08-44-49.gh-issue-128213.Y71jDi.rst Outdated
@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
…thon#132590)

Co-authored-by: Ben Hsing <blhsing@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
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.

6 participants