Automatic, portable optimization of global access

Raymond Hettinger python at rcn.com
Thu Apr 15 22:03:36 EDT 2004


[Raymond Hettinger]
> > FWIW, I've posted a brief, but powerful recipe for a bytecode
> > optimization that saves known globals as constants


[Paul]
> This looks important and will clean up a lot of code, but what happens
> if the function calls exec or eval, or assigns something into
> globals(), or whatever?

Quoth the recipe:

""" Binding should be applied selectively to those functions where
speed is important and dynamic updates are not desired (i.e. the
globals do not change). In more dynamic environments, a more
conservative approach is to set builtin_only to True so that only the
builtins get optimized (this includes functions like len(), exceptions
like IndexError, and constants like True or False).
"""


Raymond



More information about the Python-list mailing list