◐ Shell
reader mode source ↗
Skip to content

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

Open
eendebakpt wants to merge 33 commits into
python:mainfrom
eendebakpt:fast-bytes-creation-from-list-tuple-2
Open

gh-128213: fast path for bytes creation from list and tuple#132590
eendebakpt wants to merge 33 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
  • Reduces some duplicated code between list and tuple handling

@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
@markshannon

Copy link
Copy Markdown
Member

Tuples are immutable, so why does creating a bytes object from a tuple require synchronization?

@eendebakpt

Copy link
Copy Markdown
Contributor Author

Tuples are immutable, so why does creating a bytes object from a tuple require synchronization?

Tuples indeed do not require synchronization.

In this PR exact lists and tuples use the path (using synchronization with Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST). We could split the path, but I suspect the performance gain for tuples would be minimal.

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants