a pyrex-inspired for-i-from-1-to-n construct backported to Python.Good idea? Bad Idea? PEP?
Skip Montanaro
skip at pobox.com
Wed Apr 2 10:26:45 EST 2003
Peter> I just scanned a few tens of thousands of lines of our code, and
Peter> as near as I can tell only 13 cases out of over 160 instances of
Peter> "for" loops are using range() or xrange().
Similar numbers here: 146 out of 898.
It appears the builtins namespace (or at least foreign modules' namespaces)
will get somewhat less dynamic -- just enough less that the byte compiler
can tell if an instance of x?range() is calling the usual builtin instead of
a shadow copy -- so tools that care will be able to optimize "for i in
range(x)" just as well as the pyrex syntax. There have been discussions
recently about this topic in python-dev. Also, one of the sprints at PyCon
was aimed at a new version of the bytecode compiler, probably one which
generates code from an abstract syntax tree, allowing easier analysis (and
thus optimization) before generation of bytecode. So instead of
LOAD_GLOBAL range
the bytecode might be
LOAD_BUILTIN range
which tools like Psyco can detect can use to their advantage.
Skip
More information about the Python-list
mailing list