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

Erik Gorset erik at medallia.com
Wed Aug 22 14:01:27 CEST 2007

On Aug 22, 2007, at 7:56 AM, David Cournapeau wrote:
> 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.

The self technology is extremely interesting. For more information,  
you can
read Urs thesis [0], which is the bases for the cool optimization  
tricks in the
strongtalk vm [1]. The important trick here is that the vm is able to do
optimistic inlining based on type feedback during runtime, and  
the compiled code when it guesses wrong or when you enter the debugger.

I guess you can do the same thing with partial evaluation if you  
gather enough
runtime statistics to figure out which functions to specialize/inline.

More specific for your example, it will result in code looking  
something like this:

class A_compiled:
     def foo(self):
         if type(self) == A:
             return None # _foo has been inlined
             return self._foo() # uncommon case

Of course, the higher up you can start inlining, the less calls is  
needed and
better performance is achieved:

a = obj.foo()

turns into:

if type(obj) == A:
     a = None
     a = obj.foo()

[0] http://www.cs.ucsb.edu/~urs/oocsb/self/papers/urs-thesis.html
[1] http://strongtalk.org/

- Erik Gorset
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1962 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20070822/e3373d89/attachment.bin>

More information about the Pypy-dev mailing list