[1/2] let's use __slots__
I quote http://docs.python.org/ref/slots.html:
By default, instances of both old and new-style classes have a dictionary
for attribute storage. This wastes space for objects having very few
instance variables. The space consumption can become acute when creating
large numbers of instances.
And we create a lot of objects...
Also, as shown in [1], variables declared with slots are accessed ~ 2 times
faster in presence of a lot of subclasses. For the reference here are timings:
===================================
*** INSTANCE VAR ACCESS TIMES ***
===================================
cls cls(BB) note
E: 53.26 / 69.18 class var (just for reference -- can *not* be used)
I: 65.34 / 77.14 __slots__
F: 69.42 / 173.68 inst var
G: 67.95 / 173.70 inst var (+ another inst vars)
H: 68.27 / 173.89 inst var & empty __getattr__
J: 50.11 / 175.43 inst var (old class)
K: 50.25 / 181.62 __slots__ (old class)
C: 200.44 / 209.32 @property
D: 99.96 / 319.67 __getattr__ (cached)
d: 648.30 / 883.24 __getattr__
So let's use __slots__
[1] http://landau.phys.spbu.ru/~kirr/cgi-bin/hg.cgi/py-fast-property/
12 files changed: