Closed lluissalord closed 11 months ago
The slots implementation did cause a lot of trouble. See https://github.com/c0fec0de/anytree/issues/77. Therefore i will not implement __slots__
. Will think about a duplicate of NodeMixin
with __slots__
named NodeMixinSlotted
It is more complicated.
Thanks for your contribution and sorry for the delay.
Thanks for your contribution and sorry for the delay.
Thanks to you for implementing it 😄
The usage of
__slots__
is highly recommended in order to reduce memory usage on classes, even more for the ones which are used a lot of time as it could beNodeMixin
. The benefit here is that__dict__
is not generated then and a lot of memory is saved with this. Besides, with this change any class which inheritNodeMixin
can now benefit of not creating__dict__
and reduce the memory usage, otherwise child classes cannot reduce memory with this trick if the parent class does not implement it too.However, the rest of the classes of this package which inherit from
NodeMixin
should not use__slots__
because they benefit from the flexibility of__dict__
. Hence, this benefit is only for implementations which use directlyNodeMixin
, as mine.In order to set some statistics, in my implementation, the use of this change help us reduce the memory usage of the custom node classes by 49,91% and by 71,85%. Hence, as these classes are highly used on my implementation this can represent a lot of MBs reduction on memory usage.