[Python-Dev] Speed up function calls
Neal Norwitz
nnorwitz at gmail.com
Tue Jan 25 00:48:51 CET 2005
On Tue, 25 Jan 2005 00:30:44 +0100, "Martin v. Löwis"
<martin at v.loewis.de> wrote:
> Neal Norwitz wrote:
> >>Where are the Py_DECREFs done for the function arguments?
> >
> > The original code path still handles the Py_DECREFs.
> > This is the while loop at the end of call_function().
>
> Can you please elaborate?
I'll try. Do you really trust me, given my first explanation was so poor? :-)
EXT_POP() modifies stack_pointer on the stack. In call_function(),
stack_pointer is PyObject ***. But in new_fast_function(), stack_pointer
is only PyObject **. So the modifications by EXT_POP to stack_pointer
(moving it down) are lost in new_fast_function(). So when it returns
to call_function(), the stack_pointer is still at the top of the stack.
The while loop pops off the arguments.
If there was a ref leak, this scenario should demonstrate the refs increasing:
>>> isinstance(5, int)
True
[25363 refs]
>>> isinstance(5, int)
True
[25363 refs]
>>> isinstance(5, int)
True
[25363 refs]
The current code is not optimal. new_fast_function() should take PyObject***
and it should also do the DECREF, but I had some bugs when I tried to get
that working, so I've deferred fixing that. It ought to be fixed though.
HTH,
Neal
More information about the Python-Dev
mailing list