René's URL Explorer Experiment


Title: Avoid creating argument tuples when calling slot wrappers · Issue #162258 · python/cpython · GitHub

Open Graph Title: Avoid creating argument tuples when calling slot wrappers · Issue #162258 · python/cpython

X Title: Avoid creating argument tuples when calling slot wrappers · Issue #162258 · python/cpython

Description: Feature or enhancement Python wrapper_descriptor objects often wrap simple operations that are fast such as setting an attribute on an object. Calling them, however, currently constructs two tuples which often takes longer than the opera...

Open Graph Description: Feature or enhancement Python wrapper_descriptor objects often wrap simple operations that are fast such as setting an attribute on an object. Calling them, however, currently constructs two tuples...

X Description: Feature or enhancement Python wrapper_descriptor objects often wrap simple operations that are fast such as setting an attribute on an object. Calling them, however, currently constructs two tuples...

Opengraph URL: https://github.com/python/cpython/issues/162258

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Avoid creating argument tuples when calling slot wrappers","articleBody":"### Feature or enhancement\n\n\nPython [`wrapper_descriptor` objects](https://github.com/python/cpython/blob/441c010fef90ab2860ae8142cbfd1fd52f53ba75/Include/cpython/descrobject.h#L54-L58) often wrap simple operations that are fast such as setting an attribute on an object. Calling them, however, currently constructs two tuples which often takes longer than the operation.\n\nThis is particularly visible with frozen dataclasses. The decorator generates an `__init__` that calls `object.__setattr__(self, name, value)` once per field.\n\n```python3\nfrom dataclasses import dataclass\n\n@dataclass(frozen=True)\nclass frozen_triple:\n    a: int\n    b: int\n    c: int\n\nfrozen_triple(1, 2, 3)\n```\nOn `main` on my machine the `frozen_triple` instance takes ~156ns to construct. With my prototype which avoids the tuples it takes ~110ns (1.42x faster). This work generalizes gh-156250 which focused on a single slot.\n\nI propose removing the unnecessary tuples across all `wrapper_descriptor` objects by using what the interpreter already knows about exact ones with no new public API. Wrappers that take keywords, `__init__`, and `__call__`, keep one tuple.\n\n1. In `_PyObject_MakeTpCall` special case `PyWrapperDescr_Type` and call its slot wrapper directly. Change the slot wrapper core implementation to be vectorcall shaped and add a small `tp_call` wrapper around it for compatibility.\n\n   This avoids building an args tuple containing `self` that is then sliced.\n\n   prototype: https://github.com/python/cpython/commit/ba2f6455b258cb91a19fba4c732c20d89bac9488\n2. Expand the `slotdefs` array private `pytype_slotdef` entries to contain two parallel members. The existing `wrapperfunc`, which takes a tuple, and a new variant which takes vectorcall args. If the vectorcall version is non-NULL, call it. This allows for gradual migration of slots. Custom slot wrapper descriptors, such as Sage and Cython use, keep working as before.\n\n   This makes the second tuple construction optional. Until descriptor wrappers move it is still constructed when necessary.\n3. Migrate slot definitions to provide both members. The argument tuple used to keep `self` and the arguments alive during the call. In the prototype I move that responsibility to the shared call as it is relatively low overhead. Having each wrapper hold only what it needs is a possible refinement.\n\nStep 2 & 3 prototype: https://github.com/cmaloney/cpython/commit/193f25c328a\n\n### Performance\n\n| Statement | main | step 1 only | all three steps |\n|---|:---:|:---:|:---:|\n| `frozen_triple(1, 2, 3)` | 156 ns | 132 ns (1.19x faster) | 110 ns (1.42x faster) |\n| frozen dataclass, 8 fields | 356 ns | 285 ns (1.25x faster) | 222 ns (1.60x faster) |\n| `object.__setattr__(o, 'x', 1)` | 39.6 ns | 30.4 ns (1.30x faster) | 25.0 ns (1.59x faster) |\n| `int.__add__(1, 2)` | 27.1 ns | 21.5 ns (1.26x faster) | 17.6 ns (1.55x faster) |\n| `c['x'] = 1` (`collections.Counter`) | 36.4 ns | 29.4 ns (1.24x faster) | 23.2 ns (1.57x faster) |\n\nLinux x86-64, clang PGO+LTO build, pyperf.\n\nPrototype: https://github.com/python/cpython/compare/main...cmaloney:cpython:shared/exp-descrwrappper-tuple?diff=split&w\n\n### Alternatives Considered\n\n - Add a member to `PyWrapperDescrObject` which implements `vectorcall`. Adds a pointer to every `PyWrapperDescrObject` object. This works out fairly similarly performance wise but with more tradeoffs. It can be added later if needed for external project integration.\n\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n* [PEP 590](https://peps.python.org/pep-0590/) lists `wrapper_descriptor` and `method-wrapper` among the classes that \"will use the vectorcall protocol (not all of these will be changed in the initial implementation)\".\n* gh-75724 and GH-3685 (2017): \"Optimize wrapper descriptors using FASTCALL\". Closed by its author: \"these specific descriptors are rare, so the added complexity is not worth it\".\n* gh-73445 (2017): `tp_fastcall`, which included a fast wrapper in `struct wrapperbase`. Closed.\n* gh-78577 and GH-14863 (2019): inherited methods are slow in heap subclasses; the draft PR \"vectorcall for wrapper_descriptor and method-wrapper\" changed the `wrapperfunc` signature and was closed unreviewed for lack of time. The issue is still open.\n* gh-81155 (GH-13185 and GH-13781): vectorcall for `method_descriptor`, the closest precedent.\n* gh-81088: a crash from borrowed references during argument handling, the bug class the reference holding guards against.\n* gh-156250 and GH-156258: the same cost for a single slot `Counter.__setitem__`.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-162369\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/cmaloney","@type":"Person","name":"cmaloney"},"datePublished":"2026-11-19T08:31:01Z","url":"https://github.com/python/cpython/issues/162258"}

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/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6ab2f38b-592e-48c1-7bf5-c51a2ead2969
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA206:2E124E:34A6F3C:434C387:6B01EC38
html-safe-nonce029eb0484c373370dadbee5308e9aab3b070a173d65cbd3a9dfc19b86f0be5a7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjA2OjJFMTI0RTozNEE2RjNDOjQzNEMzODc6NkIwMUVDMzgiLCJ2aXNpdG9yX2lkIjoiNTMyNzUwODE2MDkyNzQ0NzYxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacf22f109293104445ae35b98124a6fffe2be1e723a1e577098b8ef87af90ed672
hovercard-subject-tagissue:6485578427
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/162258/issue_layout
twitter:imagehttps://opengraph.githubassets.com/a2b99a8b905efbf8fdc5c5a333c5734b883908a58bf618d06327c0939b19106f/python/cpython/issues/162258
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/a2b99a8b905efbf8fdc5c5a333c5734b883908a58bf618d06327c0939b19106f/python/cpython/issues/162258
og:image:altFeature or enhancement Python wrapper_descriptor objects often wrap simple operations that are fast such as setting an attribute on an object. Calling them, however, currently constructs two tuples...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecmaloney
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
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-turbofalse
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
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/162258#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F162258
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%2Fissues%2F162258
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/162258
Reloadhttps://github.com/python/cpython/issues/162258
Reloadhttps://github.com/python/cpython/issues/162258
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
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/162258
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/162258
Avoid creating argument tuples when calling slot wrappershttps://github.com/python/cpython/issues/162258#top
https://github.com/cmaloney
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Nov 19, 2026https://github.com/python/cpython/issues/162258#issue-6485578427
wrapper_descriptor objectshttps://github.com/python/cpython/blob/441c010fef90ab2860ae8142cbfd1fd52f53ba75/Include/cpython/descrobject.h#L54-L58
gh-156250https://github.com/python/cpython/issues/156250
ba2f645https://github.com/python/cpython/commit/ba2f6455b258cb91a19fba4c732c20d89bac9488
cmaloney@193f25c328ahttps://github.com/cmaloney/cpython/commit/193f25c328a
https://github.com/python/cpython/compare/main...cmaloney:cpython:shared/exp-descrwrappper-tuple?diff=split&whttps://github.com/python/cpython/compare/main...cmaloney:cpython:shared/exp-descrwrappper-tuple?diff=split&w
PEP 590https://peps.python.org/pep-0590/
Optimize wrapper descriptors using FASTCALL #75724https://github.com/python/cpython/issues/75724
[WIP] bpo-31543: Optimize wrapper descriptors #3685https://github.com/python/cpython/pull/3685
Add tp_fastcall to PyTypeObject: support FASTCALL calling convention for all callable objects #73445https://github.com/python/cpython/issues/73445
Certain methods that heap allocated subtypes inherit suffer a 50-80% performance penalty #78577https://github.com/python/cpython/issues/78577
bpo-34396: vectorcall for wrapper_descriptor and method-wrapper #14863https://github.com/python/cpython/pull/14863
Implement PEP 590 #81155https://github.com/python/cpython/issues/81155
bpo-36974: PEP 590 #13185https://github.com/python/cpython/pull/13185
bpo-36974: separate vectorcall functions for each calling convention #13781https://github.com/python/cpython/pull/13781
Crash due to borrowed references in _PyStack_UnpackDict() #81088https://github.com/python/cpython/issues/81088
Improve performance of inherited mapping assignment slot calls #156250https://github.com/python/cpython/issues/156250
gh-156250: Speed up inherited mapping assignment slot calls #156258https://github.com/python/cpython/pull/156258
gh-162258: Use vectorcall for slot wrappers #162369https://github.com/python/cpython/pull/162369
cmaloneyhttps://github.com/cmaloney
on Nov 19, 2026https://github.com/python/cpython/issues/162258#event-36626951266
cmaloneyhttps://github.com/cmaloney
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Nov 19, 2026https://github.com/python/cpython/issues/162258#event-36626953274
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Nov 21, 2026https://github.com/python/cpython/issues/162258#issuecomment-7061887837
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/162258
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/162258
cmaloneyhttps://github.com/cmaloney
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
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.