Starting from version 1.4, Psyco exports two extension types: psyco.compact and psyco.compacttype. (In some future version, Psyco may be able to patch the features implemented by these types directly into the standard interpreter's built-in types).
__slots__
-constrained instances. For example, an instance with two integer attributes uses around 180 bytes in plain Python, and only around 44 if you use __slots__
or with psyco.compact. The advantage over __slots__
is that you don't have to know all possible attributes in advance.
x.attr=(a,b,c)
stores the individual values of a
, b
and c
directly into the instance data without building a tuple in memory.
There are a few visible differences and limitations:
__slots__
is forbidden.
__dict__
attribute returns a dictionary proxy (which however supports all dict operations, including writes).
__dict__
, a copy of the data is stored into the instance; the dict and the instance do not reflect each other's future changes (they do in plain Python).
__members__
attribute which lists the current attributes, in the order in which they have been set.
__bases__
attribute will always contain psyco.compact as the last item, even if one or several other base classes were specified.
__getslot__
, __setslot__
and __delslot__
show up for internal purposes.
__slots__
.
Note that you should not mix psyco.compacttype classes and normal classes in the same hierarchy. Although this might work, the instances will still each have an unused allocated dictionary.