ITADN

Add __slots__ to minimize memory usage

#222Pull Requestalbertca 创建于 2025-07-01
A
albertcacommented
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_inline` with simply `inline` at 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_inline` and `is_pretty` on 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.
合并状态:未合并 0 条评论