[pypy-dev] How's the JIT coming along?

David Cournapeau david at ar.media.kyoto-u.ac.jp
Wed Aug 22 07:56:15 CEST 2007

Leonardo Santagada wrote:
> Em Aug 21, 2007, às 11:22 PM, David Cournapeau escreveu:
>> I cannot speak for Garry, but I myself would be interested in pypy for
>> numerical computing in python. Basically, there are cases where numpy is
>> not enough and require coding in C. The two cases I am thinking are:
>>     - recursive algorithms: this means many functions calls, which are
>> too expensive in python (eg: imagine you have a two buffers of many
>> float x, and you want to compute f(x[i], [y[i], nu[i]) = x[i+1] = x[i] +
>> nu[i] * (x[i] - y[i]); even using ctypes for the trivial computation in
>> C kills performances because of the many calls)
>>     - algorithms which require many temporaries to be efficient in 
>> numpy.
>> Both of them, if my understanding is right, would be perfect exemples of
>> easy to optimize using JIT.
> I'm guessing here, but to my knoledge to make python functions more 
> lightweight using jit would only work by making tail call 
> optimization, but for that you can also do the "same" optimization by 
> using a explicit stack and not use function calls at all.
Mmh, tail call optimization is useful for recursion, right ? I should 
not have used recursive in my post, actually, because the recursive I am 
talking about is not really what is meant in programming. The probleme 
in my case is not so much the stack, but the function call by itself.

For example, the following python code:

class A:
    def _foo(self):
       return None
    def foo(self):
       return self._foo()

Is extremely slow compared to a compiled language like C. On my 
computer, I can only execute the above function around 1 millon times a 
second (it takes around 3500 cycles by using %timeit from ipython). This 
forces me to avoid functions in some performance intensive code, which 
is ugly. Basically, I am interested in the kind of things described 
there: http://www.avibryant.com/2006/09/index.html.


More information about the Pypy-dev mailing list