Performance penalty for using properties?

Mike C. Fletcher mcfletch at
Sat Mar 13 09:19:33 CET 2004

Kenneth McDonald wrote:

>Can anyone comment on the performance
>costs associated with properties vs. simple attribute lookup?
They can become a significant fraction of total run-time, and often wind 
up showing as the heaviest methods in an entire application if they are 
used pervasively (i.e. every attribute of every object is a property).  
Even short runs of small systems so designed can give you 100s of 1000s 
of calls to an individual method.  OpenGLContext gets around this by 
defining an accelerator for the __get__ method of the field properties.  
At present BasicProperty doesn't have an equivalent accelerator (it has 
far more "hooks" in the get methods), but I'll likely wind up coding one 

The real problem is the getters, by the way, by far the most common 
situation is where you just want to alter the value or the name of the 
dictionary key at which it is stored.  The setters tend to be far less 
frequently called in my experience, so you can leave them as python code 
quite readily.


  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list