Performance penalty for using properties?

Mike C. Fletcher mcfletch at
Sat Mar 13 21:47:36 CET 2004

Joe Mason wrote:

>In article <mailman.350.1079165978.19534.python-list at>, Mike C. Fletcher wrote:
>>Kenneth McDonald wrote:
>>>Can anyone comment on the performance
>>>costs associated with properties vs. simple attribute lookup?

>>OpenGLContext gets around this by 
>>defining an accelerator for the __get__ method of the field properties.  
>What does "accelerator" mean in this context?  Obviously, it's something
>that speeds up __get__ calls, but ihow is that accomplished?
Accelerator in this context is a small C-coded Python extension with two 
functions.  One is a utility to retrieve a given key from an object's 
__dict__.  The other implements the __get__ operation (including lookup 
of default method on the property on value lookup failure failure).  All 
told about 100 lines of C code.

(and yes, I know accelerate is mis-spelled in the module names :) ).

>If it's a simple wrapper, that means you can blissfully ignore property
>costs until profiling shows it's a problem, which is a big win.
That's been my experience.  I coded the entire VRML97 scenegraph engine 
without the accelerator module and only added it when profiling showed 
that the __get__ method was a hot-spot for performance.  The 
non-accelerated code is still there in case the C module isn't 
available, of course.  As I said, haven't gotten to the 
accelerator-writing stage yet with BasicProperty, but I expect to soon.

Have fun,

  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list