[pypy-dev] How's the JIT coming along?
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).
> 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,
read Urs thesis , which is the bases for the cool optimization
tricks in the
strongtalk vm . 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
runtime statistics to figure out which functions to specialize/inline.
More specific for your example, it will result in code looking
something like this:
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
better performance is achieved:
a = obj.foo()
if type(obj) == A:
a = None
a = obj.foo()
- Erik Gorset
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1962 bytes
Desc: not available
More information about the Pypy-dev