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.
@vstinner
Copy link
Member Author

Benchmark:

import pyperf
import os

file = open(__file__, "rb", 0)
def func():
    file.seek(0)
    for _ in range(100):
        file.read(1)

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

file.close()

Result: Mean +- std dev: [ref] 65.8 us +- 1.0 us -> [change] 63.2 us +- 1.0 us: 1.04x faster

cc @cmaloney

@vstinner vstinner merged commit e814e6b into python:main Sep 15, 2025
47 checks passed
@vstinner vstinner deleted the pybyteswriter_fileio branch September 15, 2025 21:49
@vstinner
Copy link
Member Author

Merged. Thanks for the review @cmaloney.

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.

2 participants