Skip to content

gh-129813, PEP 782: Use PyBytesWriter in posix extension#138829

Merged
vstinner merged 1 commit intopython:mainfrom
vstinner:pybyteswriter_posix
Sep 13, 2025
Merged

gh-129813, PEP 782: Use PyBytesWriter in posix extension#138829
vstinner merged 1 commit intopython:mainfrom
vstinner:pybyteswriter_posix

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Sep 12, 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.
@vstinner
Copy link
Member Author

I ran a microbenchmark on os.read():

import pyperf
import os

file = open(__file__, "rb", 0)
fd = file.fileno()
def func():
    os.lseek(fd, 0, os.SEEK_SET)
    for _ in range(100):
        os.read(fd, 1)

runner = pyperf.Runner()
runner.bench_func('bench', func)

file.close()

Result: Mean +- std dev: [ref] 34.0 us +- 0.3 us -> [pep782] 33.6 us +- 0.3 us: 1.01x faster

So this change has no significant impact on the performance.

@vstinner vstinner merged commit af386fd into python:main Sep 13, 2025
47 checks passed
@vstinner vstinner deleted the pybyteswriter_posix branch September 13, 2025 16:57
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.

1 participant