Skip to content

Support setting tp_vectorcall for heap types #100554

Closed

Description

@davidhewitt

Feature or enhancement

The tp_vectorcall slot can be used with static types to define a more efficient implementation of __new__ / __init__. This slot does not have a typedef in typeslots.h, so it cannot currently be set for PyType_FromSpec or read using PyType_GetSlot.

In 3.12 other vectorcall functionality looks set to stabilise, so please consider adding a Py_tp_vectorcall typedef and allow heap types to set / get this member.

Pitch

Adding the ability for tp_vectorcall to be used in the limited API enables extension types to make use of the vectorcall optimisation in more functionality.

Previous discussion

I see in #85784 that tp_vectorcall is deliberately inaccessible with PyType_GetSlot because it is not part of the limited API.

If there is support for this proposal, I am happy to have a first stab at implementation.

Linked PRs

Activity

  1. encukou commented on Feb 3, 2023

    @encukou
    Member

    Just so everyone reading this is on the same page, this is about more efficient calling of the type, not of instances.
    For calling instances, the vectorcall offset can be set using a "__vectorcalloffset__" PyMemberDef (see the end of the docs section, and read the linked docs carefully -- vectorcall is fast but, compared to tp_call, relatively tricky to implement).

    I haven't checked if implementing tp_vetorcall correctly is possible -- remember that it'll need to match what tp_call does, including any changes to it in future versions. The bar is higher than with static types.

    See devguide and vectorcall_limited for how to add tests for this. (If it doesn't make it into 3.12 it'll need to be in a seprarte file.) The tests should show that it's possible to correctly use the feature with limited API, as well as cover any edge cases.

  2. wjakob commented on Aug 25, 2024

    @wjakob
    Contributor

    I'd like to second this feature request. I was just looking into using vector calls to accelerate object construction for nanobind and realized that it's not possible in the stable API because of the missing type slot.

  3. added a commit that references this issue on Sep 13, 2024
  4. added 2 commits that reference this issue on Sep 13, 2024
  5. added a commit that references this issue on Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions