[Python-ideas] [Python-Dev] Making builtins more efficient

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Feb 22 02:25:56 CET 2007

Steven Elliott wrote:

> What I have in mind may be close to what you are suggesting above.

My idea is somewhat more uniform and general than that.

For the module dict, you use a special mapping type that
allows selected items to be accessed by an index as well
as a name. The set of such names is determined when the
module's code is compiled -- it's simply the names used
in that module to refer to globals or builtins.

The first time a given builtin is referenced in the module,
it will be unbound in the module dict, so it is looked up
in the usual way and then written into the module dict,
so it can subsequently be retrieved by index.

The advantages of this scheme over yours are that it speeds
access to module-level names as well as builtins, and it
doesn't require the compiler to have knowledge of a
predefined set of names.

It does entail a slight semantic change, as changes made
to a builtin won't be seen by a module that has already
used that builtin for the first time. But from what Guido
has said before, it seems he is willing to accept a change
like that if it will help.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | Carpe post meridiem!          	  |
Christchurch, New Zealand	   | (I'm not a morning person.)          |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+

More information about the Python-ideas mailing list