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

Fredrik Lundh fredrik at pythonware.com
Wed May 5 08:50:33 EDT 1999


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.

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...)

</F>





More information about the Python-list mailing list