[1/2] let's use __slots__
commit53271ea7105837601a9fde03c45619550ec6684d
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Sun, 23 Mar 2008 21:17:12 +0000 (24 00:17 +0300)
committerKirill Smelkov <kirr@landau.phys.spbu.ru>
Sun, 23 Mar 2008 21:17:12 +0000 (24 00:17 +0300)
tree51b64de2283f20f282f18140c760696405da7dcd
parentbe47610848f878ca95bb89295fc9ae3ef25c3889
[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:
sympy/core/add.py
sympy/core/assumptions.py
sympy/core/basic.py
sympy/core/methods.py
sympy/core/mul.py
sympy/core/numbers.py
sympy/core/operations.py
sympy/core/power.py
sympy/core/relational.py
sympy/core/symbol.py
sympy/series/limits_series.py
sympy/series/order.py