René's URL Explorer Experiment


Title: vectercall per type · Issue #7362 · RustPython/RustPython · GitHub

Open Graph Title: vectercall per type · Issue #7362 · RustPython/RustPython

X Title: vectercall per type · Issue #7362 · RustPython/RustPython

Description: Support per-type-instance vectorcall for builtin types (dict, list, int, ...) Summary Currently, all type-object constructor calls (e.g. dict(x=1), list([1,2,3]), int("42")) go through a single vectorcall_type function, which only has a ...

Open Graph Description: Support per-type-instance vectorcall for builtin types (dict, list, int, ...) Summary Currently, all type-object constructor calls (e.g. dict(x=1), list([1,2,3]), int("42")) go through a single vec...

X Description: Support per-type-instance vectorcall for builtin types (dict, list, int, ...) Summary Currently, all type-object constructor calls (e.g. dict(x=1), list([1,2,3]), int("42")) go through a ...

Opengraph URL: https://github.com/RustPython/RustPython/issues/7362

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"vectercall per type","articleBody":"# Support per-type-instance vectorcall for builtin types (dict, list, int, ...)\n\n## Summary\n\nCurrently, all type-object constructor calls (e.g. `dict(x=1)`, `list([1,2,3])`, `int(\"42\")`) go through a single `vectorcall_type` function, which only has a fast path for `type(x)` and falls back to the generic `PyType::call` slow path for everything else. This means every builtin type constructor pays the cost of `slot_new(args.clone())` + `slot_init(args)` dispatch, including an unnecessary `args.clone()`.\n\nCPython avoids this by giving each `PyTypeObject` its own `tp_vectorcall` function pointer. When you call `dict(...)`, CPython reads `PyDict_Type.tp_vectorcall` (= `dict_vectorcall`) directly, bypassing the generic `type.__call__` → `__new__` + `__init__` chain entirely. Over 15 builtin types have dedicated vectorcall implementations.\n\n## Current Architecture in RustPython\n\n```\ndict(x=1)\n  → PyCallable::new(dict_type_obj)\n  → obj.class() = type (metatype)\n  → type.slots.vectorcall = vectorcall_type\n  → vectorcall_type: not type(x), so fallback\n  → PyType::call(dict_type, args)\n    → slot_new(args.clone())    ← unnecessary clone\n    → slot_init(args)\n```\n\nEach `PyType` instance already has its own `slots: PyTypeSlots` with `vectorcall: AtomicCell\u003cOption\u003cVectorCallFunc\u003e\u003e`, but the dispatch path never reads it. `vectorcall_type` receives the type object as its first argument but ignores the type's own `slots.vectorcall`.\n\n## Proposed Solution\n\n### 1. Modify `vectorcall_type` to dispatch per-type vectorcall\n\nIn `crates/vm/src/builtins/type.rs`, add a branch that checks the called type's own `slots.vectorcall`:\n\n```rust\nfn vectorcall_type(...) -\u003e PyResult {\n    let zelf: \u0026Py\u003cPyType\u003e = zelf_obj.downcast_ref().unwrap();\n\n    if zelf.is(vm.ctx.types.type_type) {\n        // type(x) fast path (existing)\n        ...\n    } else if let Some(type_vc) = zelf.slots.vectorcall.load() {\n        // Per-type vectorcall: dict_vectorcall, list_vectorcall, etc.\n        return type_vc(zelf_obj, args, nargs, kwnames, vm);\n    }\n\n    // Fallback to PyType::call\n    ...\n}\n```\n\nThe `else if` structure prevents infinite recursion: when `zelf` is `type_type` itself, we never read `zelf.slots.vectorcall` (which would be `vectorcall_type` again).\n\n### 2. Clear vectorcall on `__init__`/`__new__` override\n\nIn `crates/vm/src/types/slot.rs`, when `update_slot` processes `TpInit` or `TpNew` with `ADD=true`, also clear `self.slots.vectorcall.store(None)`.\n\nThis ensures subclasses that override `__init__` or `__new__` don't inherit an incorrect per-type vectorcall. For example, `class MyDict(dict): def __init__(self, ...): ...` must NOT use `dict_vectorcall`, which would skip the Python `__init__` override.\n\n### 3. Implement and register per-type vectorcall functions\n\nEach builtin type gets a dedicated vectorcall function registered in its `init()`:\n\n| Type | File | Pattern |\n|------|------|---------|\n| `dict` | `builtins/dict.rs` | DefaultConstructor + Initializer (skip `slot_new`, pass args only to `slot_init`) |\n| `list` | `builtins/list.rs` | Constructor |\n| `tuple` | `builtins/tuple.rs` | Constructor |\n| `int` | `builtins/int.rs` | Constructor |\n| `float` | `builtins/float.rs` | Constructor |\n| `str` | `builtins/pystr.rs` | Constructor |\n| `bool` | `builtins/bool_.rs` | Constructor |\n| `set` | `builtins/set.rs` | DefaultConstructor + Initializer |\n| `frozenset` | `builtins/set.rs` | Constructor |\n\nThe key optimization for `DefaultConstructor + Initializer` types (like `dict`, `set`) is avoiding the `args.clone()` in `PyType::call` line 2216 — since `Default::default()` needs no args, we construct the object first, then pass args only to `slot_init`.\n\n## Inheritance Behavior\n\n- Vectorcall is already inherited alongside `call` via `copyslot_if_none` in `slot_defs.rs` (lines 574-577)\n- `class MyDict(dict): pass` → inherits `dict_vectorcall` ✓\n- `class MyDict(dict): def __init__(self, ...): ...` → vectorcall cleared to `None`, falls back to `PyType::call` ✓\n- Custom metaclass with `__call__` override → vectorcall cleared on metaclass, per-type vectorcall never reached ✓\n\n## Key Files\n\n- `crates/vm/src/builtins/type.rs` — `vectorcall_type` dispatch modification\n- `crates/vm/src/types/slot.rs` — `update_slot` vectorcall clearing for TpInit/TpNew\n- `crates/vm/src/types/slot_defs.rs` — `copyslot_if_none` inheritance (already correct)\n- `crates/vm/src/protocol/callable.rs` — `PyCallable::new` (no changes needed)\n- Individual builtin type files for vectorcall implementations\n\n## References\n\n- [PEP 590 – Vectorcall: a fast calling protocol for CPython](https://peps.python.org/pep-0590/)\n- CPython `Objects/typeobject.c`: `type_vectorcall`, `inherit_special`\n- CPython `Include/internal/pycore_call.h`: `_PyVectorcall_FunctionInline`, `_PyObject_VectorcallTstate`","author":{"url":"https://github.com/youknowone","@type":"Person","name":"youknowone"},"datePublished":"2026-03-05T19:54:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/7362/RustPython/issues/7362"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6018f7db-761f-1f85-790e-39ee9ba91930
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA4C0:1712DC:253685F:3051481:6A5C9B19
html-safe-nonce0622091d6acbd970b3e597df02e0df6fe55a8c8edbb3681b92cfd3f60991d347
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNEMwOjE3MTJEQzoyNTM2ODVGOjMwNTE0ODE6NkE1QzlCMTkiLCJ2aXNpdG9yX2lkIjoiMTc3MTMyNjc5MzM0MzM0MzM4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaccd852552f250776f6cca09b0fe8c2517e14490e3e6b0118f4c4fbb840ab8dd97
hovercard-subject-tagissue:4030270811
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/RustPython/RustPython/7362/issue_layout
twitter:imagehttps://opengraph.githubassets.com/798dc7470d1f01d237b9b0baf2d3f62655084e3ad3922372e87a53ce2b91938f/RustPython/RustPython/issues/7362
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/798dc7470d1f01d237b9b0baf2d3f62655084e3ad3922372e87a53ce2b91938f/RustPython/RustPython/issues/7362
og:image:altSupport per-type-instance vectorcall for builtin types (dict, list, int, ...) Summary Currently, all type-object constructor calls (e.g. dict(x=1), list([1,2,3]), int("42")) go through a single vec...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameyouknowone
hostnamegithub.com
expected-hostnamegithub.com
None5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b
turbo-cache-controlno-preview
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
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
release9c975978430e9ad293956f2bbdaf153b1bd84a99
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/RustPython/RustPython/issues/7362#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F7362
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F7362
Sign up https://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=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/issues/7362
Reloadhttps://github.com/RustPython/RustPython/issues/7362
Reloadhttps://github.com/RustPython/RustPython/issues/7362
Please reload this pagehttps://github.com/RustPython/RustPython/issues/7362
RustPython https://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Notifications https://github.com/login?return_to=%2FRustPython%2FRustPython
Fork 1.5k https://github.com/login?return_to=%2FRustPython%2FRustPython
Star 22.2k https://github.com/login?return_to=%2FRustPython%2FRustPython
Code https://github.com/RustPython/RustPython
Issues 290 https://github.com/RustPython/RustPython/issues
Pull requests 100 https://github.com/RustPython/RustPython/pulls
Discussions https://github.com/RustPython/RustPython/discussions
Actions https://github.com/RustPython/RustPython/actions
Projects https://github.com/RustPython/RustPython/projects
Models https://github.com/RustPython/RustPython/models
Wiki https://github.com/RustPython/RustPython/wiki
Security and quality 0 https://github.com/RustPython/RustPython/security
Insights https://github.com/RustPython/RustPython/pulse
Code https://github.com/RustPython/RustPython
Issues https://github.com/RustPython/RustPython/issues
Pull requests https://github.com/RustPython/RustPython/pulls
Discussions https://github.com/RustPython/RustPython/discussions
Actions https://github.com/RustPython/RustPython/actions
Projects https://github.com/RustPython/RustPython/projects
Models https://github.com/RustPython/RustPython/models
Wiki https://github.com/RustPython/RustPython/wiki
Security and quality https://github.com/RustPython/RustPython/security
Insights https://github.com/RustPython/RustPython/pulse
#7407https://github.com/RustPython/RustPython/pull/7407
vectercall per typehttps://github.com/RustPython/RustPython/issues/7362#top
#7407https://github.com/RustPython/RustPython/pull/7407
https://github.com/youknowone
youknowonehttps://github.com/youknowone
on Mar 5, 2026https://github.com/RustPython/RustPython/issues/7362#issue-4030270811
PEP 590 – Vectorcall: a fast calling protocol for CPythonhttps://peps.python.org/pep-0590/
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.