[Python-Dev] Speed up function calls (original) (raw)

Neal Norwitz nnorwitz at gmail.com
Sun Jan 23 19:39:42 CET 2005


I added a patch to SF: http://python.org/sf/1107887

I would like feedback on whether the approach is desirable.

The patch adds a new method type (flags) METH_ARGS that is used in PyMethodDef. METH_ARGS means the min and max # of arguments are specified in the PyMethodDef by adding 2 new fields. This information can be used in ceval to call the method. No tuple packing/unpacking is required since the C stack is used.

The benefits are:

The drawbacks are:

I've measured between 13-22% speed improvement (debug build on Operton) when doing simple tests like:

 ./python ./Lib/timeit.py -v 'pow(3, 5)'

I think the difference tends to be fairly constant at about .3 usec per loop.

Here's a portion of the patch to show the difference between conventions:

-builtin_filter(PyObject *self, PyObject *args) +builtin_filter(PyObject *self, PyObject *func, PyObject *seq) {

the are no other changes between METH_O and METH_ARGS

Neal



More information about the Python-Dev mailing list