danielgtaylor / danielgtaylor/python-betterproto
Optimize dataclasses with __slots__
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
[Adding \_\_slots\_\_ to a class](https://stackoverflow.com/questions/472000/usage-of-slots) improves memory usage and performance of attribute access, at the expense of not being able to set arbitrary attributes on the resulting objects.
[This project](https://github.com/starhel/dataslots/blob/master/dataslots/__init__.py) demonstrates how dataclasses can be augmented to use __slots__, whilst still having class attributes set (normally adding the __slots__ attribute to a class definition would cause an error with dataclassess that declare default values).
Making generated dataclasses use slots in this way would be a small breaking change, though I don't see how it could be too inconvenient to work with, and I expect the performance improvement would be worthwhile.
Contributor guide
Assessment
This issue has not been assessed yet.