Python IS slow ! [was] Re: Python too slow for real world

Markus Kohler markus_kohler at hp.com
Wed May 5 08:55:32 EDT 1999


Fredrik Lundh wrote:
> 
> Markus Kohler wrote:
> > > GvR:
> > > Also, it allocates each stack frame as a separate object.
> > > So that's at least two memory allocation/free operations
> > > per procedure call.
> >
> > one could build a custom allocation routine that would preallocate
> > a block of memory. If the frame objects are the same size this could
> > eliminate most of the  allocation/deallocation time.
> 
> use the source, luke:
> 
> from frameobject.c:
> 
> /* Stack frames are allocated and deallocated at a considerable rate.
>    In an attempt to improve the speed of function calls, we maintain a
>    separate free list of stack frames
> 
> ...
> 
> iirc, the self people discovered that two optimizations
> dominated everything:
> 
> -- method and block in-lining
> 
> or in other words, avoid creating new call frames whenever
> possible.  Python is already a bit better off than Smalltalk
> and Self (since the structural verbs doesn't create new
> blocks).
> 
> -- call-site caching
> 
> that is, for each call-site in the source program, keep track
> of the target used the last time.  instead of doing a dynamic
> lookup, just jump there and let the method check that "self"
> is what it expected.

This is what I was trying to describe in my proposal. 
Unfortunately I'm a poor German and english is not my native language .
and call-site was the key word I couldn't remember .. 

> 
> not sure if/how the latter can be combined with Python's
> current semantics (iirc, self uses lots of extra points to be
> able to update things when you dynamically modify classes
> and individual instances...)
> 

I think it can be applied.   

There are two strategies actually one is to the keep track fo the target
used the last time
and the other is just to keep the first target. The later has the
advantage of not needing
a lot of updates, but is probably less accurate. 
If you only track one target all this is not very diffucult to
implement. Invalidating caches if the code for
the call-site changes should be pretty easy. 

What Self does is far more difficult. It records the last <n> targets.
It does that to inline code which makes
recompiling code necessary in case the inlined code changes. 

MUCH more difficult ...

Markus
-- 
Markus Kohler  mailto:markus_kohler at hp.com




More information about the Python-list mailing list