[Python-Dev] PEP280 and my experiment

Samuele Pedroni pedronis@bluewin.ch
Sat, 14 Jun 2003 03:15:46 +0200


some consideration on PEP 280: Optimizing access to globals

	http://www.python.org/peps/pep-0280.html


after my experiment.

1) in the PEP

"
Description


     (Note: Jason Orendorff writes: """I implemented this once, long
     ago, for Python 1.5-ish, I believe.  I got it to the point where
     it was only 15% slower than ordinary Python, then abandoned it.
     ;) In my implementation, "cells" were real first-class objects,
     and "celldict" was a copy-and-hack version of dictionary.  I
     forget how the rest worked."""  Reference:
     http://mail.python.org/pipermail/python-dev/2002-February/019876.html)
"

at least now you know there is hope :) for at a minimum some 15% _speedup_
when globals/builtins are heavely involved and a wash when they are not used.

2)

"
     When a function object is created from a code object and a celldict,
     the function object creates an array of cell pointers by asking the
     celldict for cells corresponding to the names in the code object's
     co_globals.  If the celldict doesn't already have a cell for a
     particular name, it creates and an empty one.  This array of cell
     pointers is stored on the function object as func_cells.  When a
     function object is created from a regular dict instead of a
     celldict, func_cells is a NULL pointer.
"

this is probably far from ideal for closures, OTOH with the right 
infrastructure it should be possible to store created caches e.g. in code 
objects and so reuse them.

regards.