Use __slots__ on NodeMixin to reduce memory usage #196
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.