New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-91049: Introduce set vectorcall field API for PyFunctionObject #92257
base: main
Are you sure you want to change the base?
gh-91049: Introduce set vectorcall field API for PyFunctionObject #92257
Conversation
Every change to Python requires a NEWS entry. Please, add it using the blurb_it Web app or the blurb command-line tool. |
@markshannon Can you let me know if there should be any other checks in For context, this check fixes an edge case where calling function with a set vectorfield only worked with a unpacked tuple, e.g. f |
Python/ceval.c
Outdated
@@ -4792,7 +4792,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int | |||
PyObject *function = PEEK(total_args + 1); | |||
int positional_args = total_args - KWNAMES_LEN(); | |||
// Check if the call can be inlined or not | |||
if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) { | |||
if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL && ((PyFunctionObject *)function)->vectorcall == _PyFunction_Vectorcall) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this probably exceeds line length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the max line length allowed? And is there a linter I can run to handle this for me?
|
||
This PR introduces an API call where vectorcall field can be modified like so: | ||
|
||
`void PyFunction_SetVectorcall(PyFunctionObject *func, vectorcallfunc vectorcall);` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document the function in Doc/c-api/function.rst and in the NEWS entry, refer to use with:
:c:func:`PyFunction_SetVectorcall`
New public functions should also be documented in What's New in Python 3.11 > C API > New features: Doc/whatsnew/3.11.rst.
A few comments.
Have you attempted to measure the performance impact of this? (I'd expect it to be small or negligible).
Change how assertion is done Co-authored-by: Itamar Ostricher <itamarost@gmail.com>
@markshannon is there a simple way to ask a buildbot to run pyperformance comparing this against the base revision? we can do that manually, but a buildbot doing it for us would be nice :) |
circling back to @markshannon 's performance impact question. -- tldr some more details: rebased this PR onto a4460f2 and ran pyperformance on a4460f2 and on the rebased branch both baseline and branch were built using used pyperformance 1.0.5 (installed directly from GitHub) on bare metal AWS machine (Linux-5.13.0-1023-aws-x86_64-with-glibc2.31 with 72 logical CPUs), and excluded the sqlalchemy benchmarks because they tried building greenlet and failed
compare results:
thanks @ansley for doing the perf analysis on this :) |
Avoid specializing functions with overridden vectorcall field