tools.target: use slots for Channel and User types #2233
Merged
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.
Description
Tin, really. Python has this feature where you can tell it to store instance attributes in a "slot", and using it can make small objects more time- and space-efficient by eliminating the need to look up attributes in the instance's
__dict__
.This can save some significant memory when Sopel is in many and/or large channels. For example, without this patch (in bytes):
And with this patch (also in bytes):
An empty channel is reduced by nearly half, and channels with some significant user count can be reduced by some 10-15%.
I have not checked the impact of this patch on execution time, but would be glad to do so if requested.
Notes
These values were calculated using
Pympler.asizeof
(basically a recursive version ofsys.getsizeof
) in a simple test script:Checklist
make qa
(runsmake quality
andmake test
)target_sizes.py
test script, which I didn't bother to make PEP8-compliant.