Do deep inheritance trees degrade efficiency?

Terry Reedy tjreedy at udel.edu
Thu Mar 19 17:19:54 CET 2009


Terry Reedy wrote:
> Anthra Norell wrote:
>> Would anyone who knows the inner workings volunteer to clarify whether 
>> or not every additional derivation of a class hierarchy adds an 
>> indirection to the base class's method calls and attribute read-writes. 
> 
> More potential search layers rather than pointer indirection.  But I 
> doubt this is a bottleneck in very many programs.  So I would more 
> concern myself first with quickly writing correct code.

I should add that when object access time matters and the object is 
accessed repeatedly, a common solution is to bind it to a local name 
*once* and then access it via the local (which is the fastest way 
possible for CPython and, I expect, for other implementation).  This 
works for all slower access methods.

tjr




More information about the Python-list mailing list