René's URL Explorer Experiment


Title: gh-129813: Use `PyBytesWriter` in `ctypes` by maurycy · Pull Request #162260 · python/cpython · GitHub

Open Graph Title: gh-129813: Use `PyBytesWriter` in `ctypes` by maurycy · Pull Request #162260 · python/cpython

X Title: gh-129813: Use `PyBytesWriter` in `ctypes` by maurycy · Pull Request #162260 · python/cpython

Description: Write strided slices of c_char arrays and pointers w/ a PyBytesWriter. Spares a temporary allocation, a copy. Similar to #162257 I believe this is mostly a simplification, but, again, I'm surprised that's good for the memory: Result size Step Baseline peak (bytes) Patched peak (bytes) 4 KiB 2 8,225 4,129 8 MiB 2 16,777,249 8,388,641 8 MiB -1 16,777,249 8,388,641 8 MiB 1 8,388,641 8,388,641 pyperf: Type Result size Step Baseline 1 Patched 1 Baseline 2 Patched 2 array 32 B 2 36.9 ns 35.2 ns 37.6 ns 35.0 ns pointer 32 B 2 34.0 ns 32.8 ns 34.2 ns 34.2 ns array 4 KiB 2 1.18 µs 1.11 µs 1.17 µs 1.11 µs pointer 4 KiB 2 616.2 ns 566.3 ns 615.9 ns 564.2 ns array 8 MiB 2 2.36 ms 2.19 ms 2.35 ms 2.21 ms pointer 8 MiB 2 1.33 ms 1.16 ms 1.30 ms 1.15 ms array 8 MiB -1 2.40 ms 2.18 ms 2.41 ms 2.18 ms pointer 8 MiB -1 1.39 ms 1.11 ms 1.25 ms 1.11 ms array 8 MiB 1 125 µs 126 µs 145 µs 124 µs pointer 8 MiB 1 136 µs 123 µs 140 µs 134 µs (PGO+LTO, macOS arm64) pyperf import ctypes import pyperf runner = pyperf.Runner() for size, step in ((32, 2), (4096, 2), (8 << 20, 2), (8 << 20, -1), (8 << 20, 1)): length = size * abs(step) + (step < 0) array = (ctypes.c_char * length)() ctypes.memset(array, 65, length) pointer = ctypes.cast(ctypes.byref(array), ctypes.POINTER(ctypes.c_char)) key = slice(size, 0, -1) if step < 0 else slice(None, length, step) for kind, obj in (("array", array), ("pointer", pointer)): name = f"{kind} {size} B step {step}" runner.timeit(name, "obj[key]", globals={"obj": obj, "key": key}) memory import ctypes import tracemalloc for size, step in ((32, 2), (4096, 2), (8 << 20, 2), (8 << 20, -1), (8 << 20, 1)): length = size * abs(step) + (step < 0) array = (ctypes.c_char * length)() ctypes.memset(array, 65, length) pointer = ctypes.cast(ctypes.byref(array), ctypes.POINTER(ctypes.c_char)) key = slice(size, 0, -1) if step < 0 else slice(None, length, step) for kind, obj in (("array", array), ("pointer", pointer)): name = f"{kind} {size} B step {step}" tracemalloc.start() result = obj[key] _, peak = tracemalloc.get_traced_memory() tracemalloc.stop() assert len(result) == size print(name, peak) del result Issue: gh-129813

Open Graph Description: Write strided slices of c_char arrays and pointers w/ a PyBytesWriter. Spares a temporary allocation, a copy. Similar to #162257 I believe this is mostly a simplification, but, again, I'm surpr...

X Description: Write strided slices of c_char arrays and pointers w/ a PyBytesWriter. Spares a temporary allocation, a copy. Similar to #162257 I believe this is mostly a simplification, but, again, I&#39;m s...

Opengraph URL: https://github.com/python/cpython/pull/162260

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:62cfd1b4-2e40-4985-2ead-03f5ace50b23
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAAFC:22DB35:3D95E53:4E84D32:6B02009C
html-safe-nonce4923ee2d3b7238c9e69e5139a9f7d4cee3a7e6d4a7ffd3014bff10201537b60d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUZDOjIyREIzNTozRDk1RTUzOjRFODREMzI6NkIwMjAwOUMiLCJ2aXNpdG9yX2lkIjoiNzYzODkzMzA2NTI4MDEyNzEzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac95ed839bf81e35a241c04e3ecc48ff226f217a182c0b3e2c0fcae98cb4d2cd6d
hovercard-subject-tagpull_request:5391704184
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/162260/files
twitter:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
og:image:altWrite strided slices of c_char arrays and pointers w/ a PyBytesWriter. Spares a temporary allocation, a copy. Similar to #162257 I believe this is mostly a simplification, but, again, I'm surpr...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/162260/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F162260%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F162260%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/162260/files
Reloadhttps://github.com/python/cpython/pull/162260/files
Reloadhttps://github.com/python/cpython/pull/162260/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
vstinnerhttps://github.com/vstinner
python:mainhttps://github.com/python/cpython/tree/main
maurycy:ctypes-pybyteswriter-sliceshttps://github.com/maurycy/cpython/tree/ctypes-pybyteswriter-slices
Conversation 3 https://github.com/python/cpython/pull/162260
Commits 1 https://github.com/python/cpython/pull/162260/commits
Checks 62 https://github.com/python/cpython/pull/162260/checks
Files changed 1 https://github.com/python/cpython/pull/162260/files
gh-129813: Use PyBytesWriter in ctypes https://github.com/python/cpython/pull/162260/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/162260/files
8db1383 up maurycy Nov 19, 2026 https://github.com/python/cpython/pull/162260/commits/8db1383c2cfabe4f1c284c8352b8884db50f3bb3
Clear filters https://github.com/python/cpython/pull/162260/files
Please reload this pagehttps://github.com/python/cpython/pull/162260/files
Please reload this pagehttps://github.com/python/cpython/pull/162260/files
Modules/_ctypes/_ctypes.chttps://github.com/python/cpython/pull/162260/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
View file https://github.com/maurycy/cpython/blob/8db1383c2cfabe4f1c284c8352b8884db50f3bb3/Modules/_ctypes/_ctypes.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/162260/{{ revealButtonHref }}
https://github.com/python/cpython/pull/162260/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
https://github.com/python/cpython/pull/162260/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
https://github.com/python/cpython/pull/162260/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
https://github.com/python/cpython/pull/162260/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
https://github.com/python/cpython/pull/162260/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
https://github.com/python/cpython/pull/162260/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
Please reload this pagehttps://github.com/python/cpython/pull/162260/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.