[Python-Dev] Speeding up instance attribute access

Guido van Rossum guido@python.org
Mon, 11 Feb 2002 10:31:33 -0500


> Guido van Rossum <guido@python.org> writes:
> 
> > - We need fallbacks for various exceptional cases:
> 
> I think assignment to __class__ also needs to be
> considered. Therefore, it may be best if the member array is a
> separate block (not allocated with the instances).

Good point.  When __class__ is assigned and the new __class__ has a
different layout of the member array then the old, all instance
variables must be moved from the member array into a temporary dict,
and then from the temporary dict redistributed over the new member
array.  If you're lucky, the temporary dict is empty after that;
otherwise, it becomes the overflow dict.

> It might also be worthwhile to incorporate __slots__ access into that
> scheme, to avoid having to find the member descriptor in the class
> dictionary.

__slots__ are really allocated in the object, not in a separate memory
block.  But I agree it would be nice if they could somehow be integrated.

--Guido van Rossum (home page: http://www.python.org/~guido/)