PyO3 / PyO3/pyo3

Performance opportunity: support `__vectorcalloffset__` for `__call__`

Open
#4,252 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

At the moment our implementation in #[pymethods] of the __call__ member sets the tp_call slot which receives the arguments as a tuple and dictionary.

As an optimization we could instead set __vectorcalloffset__ to direct Python to use the vectorcall protocol for tp_call. I think this probably is supported on Python 3.9 and up.

See the CPython reference - https://docs.python.org/3.9/c-api/typeobj.html#c.PyTypeObject.tp_vectorcall_offset

This would be a fair bit of fiddling around in our macro code and probably also in the create_type_object implementation, however the speedup might be nice! 😄

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the #[pymethods] implementation of call and the create_type_object implementation, then consult the CPython tp_vectorcall_offset reference linked in the issue. Trace how tp_call currently receives arguments and determine the macro and type-object changes needed for the vectorcall protocol on Python 3.9 and newer. Done means call uses the vectorcall path without the current tuple and dictionary argument handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
backend-api-design, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.