botbowl
botbowl copied to clipboard
Implement __slots__ in model.py
The special attribute slots allows you to explicitly state which instance attributes you expect your object instances to have, with the expected results:
- faster attribute access.
- space savings in memory.
By doing below (on every class that's often used), we can get a significant performance increase!
@immutable_after_init
class Square:
__slots__ = 'x', 'y', '_out_of_bounds' # only new thing
x: int
y: int
_out_of_bounds: Optional[bool]
def __init__(self, x: int, y: int, _out_of_bounds=None):
self.x = x
self.y = y
self._out_of_bounds = _out_of_bounds
...
This is a good first issue for anyone who want to contribute, just make the update and make sure all tests pass! :relaxed:
I would like to work on this issue.