[Python-Dev] python optimization

Nick Coghlan ncoghlan at gmail.com
Fri Sep 16 16:09:39 CEST 2005


Neal Becker wrote:
> One possible way to improve the situation is, that if we really believe
> python cannot easily support such optimizations because the code is too
> "dynamic", is to allow manual annotation of functions.  For example, gcc
> has allowed such annotations using __attribute__ for quite a while.  This
> would allow the programmer to specify that a variable is constant, or that
> a function is pure (having no side effects).

Raymond's constant binding decorator comes pretty close to achieving that:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940

It kicks in when the def statement is executed, rather than when the module is 
compiled, but that difference is not uncommon in Python (you don't know what 
half the names refer to until the top-level of the module is executed).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.blogspot.com


More information about the Python-Dev mailing list