Skip to content

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Sep 15, 2025

Replace PyBytes_FromStringAndSize(NULL, size) and _PyBytes_Resize() with the new public PyBytesWriter API.

Replace PyBytes_FromStringAndSize(NULL, size) and _PyBytes_Resize()
with the new public PyBytesWriter API.
@kumaraditya303
Copy link
Contributor

This is a performance critical function, please check that this has no slowdown on microbenchmark.

@vstinner
Copy link
Member Author

This is a performance critical function, please check that this has no slowdown on microbenchmark.

Do you have advises on how to write such benchmark?

Benchmarks on similar functions:

Creating a writer takes less than 30 ns, so time is dominated by I/O operations.

@vstinner
Copy link
Member Author

I wrote a similar change to use PyBytesWriter in socket.socket.recv(): #139097 (comment)

@gpshead
Copy link
Member

gpshead commented Sep 18, 2025

I am not worried about performance on this change. The more modern code (1) has the same complexity as the older code and (2) the CPU performance should already be dominated by the decryption that happens to generate the data being read in the first place - not our potential data copy if an internal resize were to move something.

@vstinner vstinner merged commit 446587c into python:main Sep 18, 2025
51 checks passed
@vstinner vstinner deleted the pybyteswriter_ssl_read branch September 18, 2025 14:54
@vstinner
Copy link
Member Author

Merged, thanks for reviews.

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.

3 participants