__slots__の使い道

まずはpython リファレンスでの__slots__の説明


3.4.2.4. __slots__

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.

The default can be overridden by defining __slots__ in a new-style class definition. The __slots__ declaration takes a sequence of instance variables and reserves just enough space in each instance to hold a value for each variable. Space is saved because __dict__ is not created for each instance.

python のオブジェクトは内部的にdictionaryを持っていて、そこに変数を保持している。
そのdictionaryの生成には、必ずしも宣言する変数分のスペースではなく余分に確保している。
その無駄を省けるのが__slots__だ。あらかじめ、宣言する変数を教えておくことで、メモリを最小限に抑えることが
できる。
生成するオブジェクトが大量の場合はメモリ節約に効果があるだろう。
しかし、変数へのアクセスの速度は少しさがるとか。

こちらのサイト「__slots__を使用したオブジェクトは生成は速いが、属性値の参照が少々遅くなる」で、実験されているので参考にしました。