[issue46323] Use _PyObject_Vectorcall in Modules/_ctypes/callbacks.c

hydroflask report at bugs.python.org
Mon Feb 7 11:20:33 EST 2022


hydroflask <hydroflask at yqxmail.com> added the comment:

Just to clarify further, the original benchmark by corona10 did indeed lead to `_CallPythonObject` being invoked but it was not quite the normal use-case. In the original benchmark it invoked the generated ctypes thunk via Python so as vstinner said it was doing this:

    Python -> converters -> thunk-> _CallPythonObject -> converters-> Python

Namely using `PyCFuncPtr_call` to invoke the thunk generated by `_ctypes_alloc_callback`. Normally when invoking C functions via `PyCFuncPtr_call` it looks like this:

    Python -> converters -> C_function

In the original benchmark setup no significant reduction in runtime was observed by this patch.  I noticed that it was not a typical use of `_CallPythonObject`, where instead it would be a top-level C function calling back into Python. Something like this:

    C -> thunk -> _CallPythonObject() -> Python

The benchmark I provided exercises that use case and the >=10% reduction in runtime was observed. Thanks to both corona10 and vstinner, I appreciate their effort in this issue.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46323>
_______________________________________


More information about the Python-bugs-list mailing list