René's URL Explorer Experiment


Title: gh-127295: ctypes: Switch field accessors to fixed-width integers by encukou · Pull Request #127297 · python/cpython · GitHub

Open Graph Title: gh-127295: ctypes: Switch field accessors to fixed-width integers by encukou · Pull Request #127297 · python/cpython

X Title: gh-127295: ctypes: Switch field accessors to fixed-width integers by encukou · Pull Request #127297 · python/cpython

Description: See the issue. This refactoring has a miniscule but consistent performance benefit (1.01x geometric mean; edit: 46 cases slower & 415 faster). See my bench script & results. Thanks @vstinner for pyperf and instructions for isolating CPU cores! For the repetitive parts, this uses a combination of macros and Argument Clinic for code generation (inline, so one can easily inspect the results). This is the most readable/maintainable of various approaches I tried. (No, I'm not a fan of the giant macros, but it beats both code generated from f-strings that lack syntax highlighting, and external multiple-include files. Oh, and the /////////// lines make it easy to see misplaced backslashes.) Several related changes are included: Pass a meaningful size argument, rather than zero, to non-bitfield accessors. (This would be great to have for size-generic functions, and it should be a private implementation detail. I want to do this now and get the asserts in the wild, to see if I missed someone who's relying on the detail.) Use a switch in _ctypes_get_fielddesc, rather than a linear search. (This requires that there are now several boring chunks with a line for each of the format codes, sbBcdCEFgfhHiIlLqQPzuUZXvO, but Argument Clinic makes this bearable.) Rearrange struct fielddesc to move all the accessors together, making code generation a bit easier Motley consistency improvements, like changing BSTR in function names to its code char X, to match the other accessors Issue: gh-127295

Open Graph Description: See the issue. This refactoring has a miniscule but consistent performance benefit (1.01x geometric mean; edit: 46 cases slower & 415 faster). See my bench script & results. Thanks @vstinne...

X Description: See the issue. This refactoring has a miniscule but consistent performance benefit (1.01x geometric mean; edit: 46 cases slower & 415 faster). See my bench script & results. Thanks ...

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

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:ca2d97e4-e2c9-1766-18db-0d8edeb74b86
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9322:27F8BD:536A9:6E925:6B022064
html-safe-nonced8f88caef7c0fb8481e7fa2bff405f5bfcad6759700f135e701d8ddc70d3ef23
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MzIyOjI3RjhCRDo1MzZBOTo2RTkyNTo2QjAyMjA2NCIsInZpc2l0b3JfaWQiOiI3MDMxMTAwNjEzNDIxMzEwMDUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac4d75fabfb359c0f1a1c4b8af0f2da325796d8d7ab6f396b80aa89c8926ec99bb
hovercard-subject-tagpull_request:2201219599
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/127297/files
twitter:imagehttps://avatars.githubusercontent.com/u/302922?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/302922?s=400&v=4
og:image:altSee the issue. This refactoring has a miniscule but consistent performance benefit (1.01x geometric mean; edit: 46 cases slower & 415 faster). See my bench script & results. Thanks @vstinne...
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 full-width
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/127297/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F127297%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%2F127297%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/127297/files
Reloadhttps://github.com/python/cpython/pull/127297/files
Reloadhttps://github.com/python/cpython/pull/127297/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
encukouhttps://github.com/encukou
python:mainhttps://github.com/python/cpython/tree/main
encukou:ctypes-fixinthttps://github.com/encukou/cpython/tree/ctypes-fixint
Conversation 35 https://github.com/python/cpython/pull/127297
Commits 20 https://github.com/python/cpython/pull/127297/commits
Checks 0 https://github.com/python/cpython/pull/127297/checks
Files changed https://github.com/python/cpython/pull/127297/files
Please reload this pagehttps://github.com/python/cpython/pull/127297/files
gh-127295: ctypes: Switch field accessors to fixed-width integers https://github.com/python/cpython/pull/127297/files#top
Show all changes 20 commits https://github.com/python/cpython/pull/127297/files
eeb0d4e Consistently pass the size to getfunc/setfunc encukou Nov 19, 2024 https://github.com/python/cpython/pull/127297/commits/eeb0d4e1fd96c58a1de76c1d974684c1e5e91f10
e33c929 Switch to fixed-width integers encukou Nov 22, 2024 https://github.com/python/cpython/pull/127297/commits/e33c92953b363454351b4073424e813e17b7415d
a11c0d9 Remove comment for obsolete idea encukou Nov 26, 2024 https://github.com/python/cpython/pull/127297/commits/a11c0d9b596b5c9e292b6420b455ffde13f22b51
c69b65f Fix the size argument encukou Nov 26, 2024 https://github.com/python/cpython/pull/127297/commits/c69b65fe72f02a17d4e5ededa589f3bbe6c9d55a
eb8cf98 Re-run Clinic encukou Nov 26, 2024 https://github.com/python/cpython/pull/127297/commits/eb8cf98e1e9646c8c71d80d650acc364b3621fcb
b9ed727 Regen Clinic encukou Nov 26, 2024 https://github.com/python/cpython/pull/127297/commits/b9ed7278328b6bf75d82408048fa2e4049e5649e
7cbe57c Specify signedness of the FFI types, don't match the C types encukou Nov 26, 2024 https://github.com/python/cpython/pull/127297/commits/7cbe57ceca172ca729ebdc97facdb25459ea8472
144a3b0 Avoid compiler warnings encukou Nov 26, 2024 https://github.com/python/cpython/pull/127297/commits/144a3b0544d04bf5290e7b546e59876334d4982a
fcae66b Silence the GCC warning in a more local way. It's a GCC bug. encukou Nov 26, 2024 https://github.com/python/cpython/pull/127297/commits/fcae66bf1f432d7ba8fa85f60e018986bc8ec461
05ba989 Apply suggestions from code review encukou Dec 6, 2024 https://github.com/python/cpython/pull/127297/commits/05ba9899bcd62b991d51bc3ffad385dd1d79915b
7c08d60 Add parens around macro argument encukou Dec 6, 2024 https://github.com/python/cpython/pull/127297/commits/7c08d60da964ae868549eed0296182a2816a0b17
50c82be Fix refcounting for _CTYPES_DEBUG_KEEP builds encukou Dec 6, 2024 https://github.com/python/cpython/pull/127297/commits/50c82bed90acfb44043338a567eda51b47cec65f
7375c09 Consistency in comments. Why not. encukou Dec 6, 2024 https://github.com/python/cpython/pull/127297/commits/7375c09dc4810daa3e5ad1957ea2f985e890b3b0
6e8a4de Merge in the main branch encukou Dec 6, 2024 https://github.com/python/cpython/pull/127297/commits/6e8a4de0f8b3dd41290178b6446fe8aabed41715
870a038 Include & use `bool` rather than `_Bool` encukou Dec 9, 2024 https://github.com/python/cpython/pull/127297/commits/870a03849990e1cc45c7a6fe9c2bc654d7cc7258
1b41ace Use a mutex around _ctypes_init_fielddesc encukou Dec 9, 2024 https://github.com/python/cpython/pull/127297/commits/1b41ace5734297732c89cc53d222fea718ce9533
07d7ded Merge in the main branch encukou Dec 13, 2024 https://github.com/python/cpython/pull/127297/commits/07d7ded17616cd9c4363b5fcbce8f0e6f4e47a58
34098c3 Nitpick: Use true/false for bool encukou Dec 13, 2024 https://github.com/python/cpython/pull/127297/commits/34098c351dd1ec217ce7360e5d3cf9ea4c3711a1
5155293 Avoid unaligned load encukou Dec 18, 2024 https://github.com/python/cpython/pull/127297/commits/5155293361de5db6abe76b50a6510452441e4fb7
821a7b8 Merge branch 'main' into ctypes-fixint encukou Dec 19, 2024 https://github.com/python/cpython/pull/127297/commits/821a7b82e6e750f9fcb054d2bed5eed3f332e020
Clear filters https://github.com/python/cpython/pull/127297/files
Please reload this pagehttps://github.com/python/cpython/pull/127297/files
Please reload this pagehttps://github.com/python/cpython/pull/127297/files
_ctypes.c https://github.com/python/cpython/pull/127297/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
callbacks.c https://github.com/python/cpython/pull/127297/files#diff-706e65ee28911740bf638707e19578b8182e57c6a8a9a4a91105d825f95a139d
cfield.c https://github.com/python/cpython/pull/127297/files#diff-2952ec5c776412a52a7a69a6cf735e480d7454e3862d2b8e02f34c927f600aa1
ctypes.h https://github.com/python/cpython/pull/127297/files#diff-53f61eb1ad6b25b3aff25b54b4df5004a1f1137ca1d2aae4c7e31fc00ec6e9f8
Modules/_ctypes/_ctypes.chttps://github.com/python/cpython/pull/127297/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
View file https://github.com/encukou/cpython/blob/821a7b82e6e750f9fcb054d2bed5eed3f332e020/Modules/_ctypes/_ctypes.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/127297/{{ revealButtonHref }}
https://github.com/python/cpython/pull/127297/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
https://github.com/python/cpython/pull/127297/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
https://github.com/python/cpython/pull/127297/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
https://github.com/python/cpython/pull/127297/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
Modules/_ctypes/callbacks.chttps://github.com/python/cpython/pull/127297/files#diff-706e65ee28911740bf638707e19578b8182e57c6a8a9a4a91105d825f95a139d
View file https://github.com/encukou/cpython/blob/821a7b82e6e750f9fcb054d2bed5eed3f332e020/Modules/_ctypes/callbacks.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/127297/{{ revealButtonHref }}
https://github.com/python/cpython/pull/127297/files#diff-706e65ee28911740bf638707e19578b8182e57c6a8a9a4a91105d825f95a139d
https://github.com/python/cpython/pull/127297/files#diff-706e65ee28911740bf638707e19578b8182e57c6a8a9a4a91105d825f95a139d
Please reload this pagehttps://github.com/python/cpython/pull/127297/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.