FR: Generate __slots__ for objects
ferozco opened this issue · 1 comments
ferozco commented
By default, Python uses a dict to store the fields of a class. This allows for fields to be dynamically added to an object at the cost of runtime performance and memory usage.
We can avoid the runtime costs by definin __slots__
in our objects. This tells Python to only allocate enough space for the predefined set of fields.
Links:
https://blog.usejournal.com/a-quick-dive-into-pythons-slots-72cdc2d334e
http://book.pythontips.com/en/latest/__slots__magic.html