[Patches] [ python-Patches-1107887 ] Speed up function calls/can add more introspection info

SourceForge.net noreply at sourceforge.net
Sun Jan 23 19:32:06 CET 2005


Patches item #1107887, was opened at 2005-01-23 13:32
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1107887&group_id=5470

Category: Core (C code)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Neal Norwitz (nnorwitz)
Assigned to: Nobody/Anonymous (nobody)
Summary: Speed up function calls/can add more introspection info

Initial Comment:
This patch adds a new method type (flags) METH_ARGS
(yeah, the name could be better) 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 original patch only modifies Python/bltinmodule.c.
 If the approach is desirable, Objects/*.c should be
modified and so should code in Modules/ (probably).

The benefits are:
 * faster function calls
 * simplify function call machinery by removing
METH_NOARGS, METH_O, and possibly METH_VARARGS
 * more introspection info for C functions (ie, min/max
arg count)

The primary drawback is:
 * the defn of the MethodDef (# args) is separate from
the function defn
 * potentially more error prone to write C methods???

I've measured between 13-22% speed improvement 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.

I'm not sure of the effect on memory usage.  I wouldn't
expect it to be much in either direction.

Note:  This patch does not make the min/max arg count
available to Python code.  If this patch is accepted,
that seems like it should also be done.

It's possible that METH_VARARGS may not be able to go away.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1107887&group_id=5470


More information about the Patches mailing list