[Python-Dev] [ python-Patches-876206 ] scary frame speed hacks

Raymond Hettinger python at rcn.com
Tue Mar 2 14:42:08 EST 2004


> [Skip]
> > Why not a list of pre-made frames for each code block (default
length
> 1)?
> 
> Or, IOW, per-code-block frame freelists (plural).  Recursive
generators
> have
> gotten quite popular in my code <wink>.
> 
> BTW, if a gazillion distinct functions run when starting up a large
app,
> do
> we hang on to the memory for their gazillion distinct frames forever?
> Recycling from a common frame pool has memory benefits in cases other
than
> just recursion.  Experiment:  run test.py from a Zope 2 or Zope 3
> checkout,
> and look at highwater memory consumption with and without the patch.

We should look at keeping the freelist and when a code block needs a
frame,
it can request the one that it last used if available.  Roughly:

def getblock(idnum):
   if idnum in freelist:
       return freelist[id]
   if len(freelist):
       return freelist.pop()
   return makeNewFrame()


Raymond




More information about the Python-Dev mailing list