Add __slots__ to minimize memory usage #222
Open
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.
Add slots makes python not to instantiate a dict for each object which improves memory usage.
This is specially important with applications that create a large number of tags.
The only issue with slots is that one cannot have a class attribute that has the same name as an object attribute. This causes an issue with is_inline and is_pretty.
In the current patch I simply commented the code that allows to change those attributes in a given object instance (it can be declared at class-level only), but it can be solved either by renaming
is_inlinewith simplyinlineat class-level or object-level.I can implement either one or the other, I don't care, but of course any of those changes means a backwards compatibility issue. Who do we want to annoy: those declaring new classes or those redefining
is_inlineandis_prettyon object instantiation?Apart from the slots, which I could verify that really reduce the memory footprint, I did some minor changes cosmetic changes which I can revert.