Skip to content

[Python] Usage of __slots__ or @dataclass(slots=True) in python classes for reducing memory usage and performance improvement  #56

@Martin15135215

Description

@Martin15135215

I saw the Pycon 2016 talk from Nina Zakharenko about Memory Management in Python and at the 21:19 min, she introduced the dunker slots attribute to define the attributes. Because with that, you can't assign at runtime new attributes to the class instance. This reduces the memory usage and improves performance.

To reduce boilerplate, there is also the possibility to use @dataclass(slots=True) as shown in this video, see also the python documentation → https://docs.python.org/3.10/library/dataclasses.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions