Skip to content

Use METH_FASTCALL protocol in Python bindings #49476

Open

Description

@robieta

🚀 Feature

Move python bindings to use FASTCALL methods.

Motivation

Python 3.7 introduced the METH_FASTCALL and METH_FASTCALL | METH_KEYWORDS binding methods. (API) They skip tuple/dict construction and simply pass C arrays, and based on my testing in #48965 can save ~15ns compared to METH_VARARGS. (I have not tested the kwargs version, but I would expect skipping a dictionary to be even better.)

Pitch

#48965 adds a wrapper in python_compat.h so that we can rewrite endpoints to use _PyCFunctionFast but fall back to tuple wrapping for 3.6. This would need to be applied to all varargs functions and an analog would need to be written for functions that take kwargs. Given that most binding comes from the torch python arg parser, that will likely need to be converted as well. (I'm not sure how much work that would be.)

Activity

  1. added
    feature
    module: pybind
    on Dec 18, 2020
  2. mrshenli commented on Dec 18, 2020

    @mrshenli
    Contributor

    adding "triage review" to discuss plans

  3. VitalyFedyunin commented on Dec 28, 2020

    @VitalyFedyunin
    Contributor

    Good to go as per discussion.

  4. added
    triaged
    on Dec 29, 2020
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

    featuremodule: pybindtriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions