FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-129813, PEP 782: Use PyBytesWriter in ssl.MemoryBIO by vstinner · Pull Request #139113 · python/cpython · GitHub

Repository navigation

gh-129813, PEP 782: Use PyBytesWriter in ssl.MemoryBIO - #139113

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:pybyteswriter_memorybio
Sep 18, 2025
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:pybyteswriter_memorybio

Conversation

vstinner commented Sep 18, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

Benchmark:

import ssl
import pyperf

bio = ssl.MemoryBIO()

def bench(size):
    bio.write(b'x' * size)
    data = bio.read(size)
    if len(data) != size:
        raise Exception

runner = pyperf.Runner()
for size in (1, 10, 100, 1_000, 10_000):
    runner.bench_func(f'read {size:,}B', bench, size)

Result:

Benchmark ref pep782
read 1B 267 ns 239 ns: 1.12x faster
read 10B 281 ns 276 ns: 1.02x faster
read 100B 276 ns 286 ns: 1.04x slower
read 1,000B 380 ns 374 ns: 1.02x faster
Geometric mean (ref) 1.02x faster

Benchmark hidden because not significant (1): read 10,000B

vstinner merged commit d6a6fe2 into python:main Sep 18, 2025
47 checks passed
vstinner deleted the pybyteswriter_memorybio branch September 18, 2025 12:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL