[Python] Usage of __slots__ or @dataclass(slots=True) in python classes for reducing memory usage and performance improvement #3857
Martin15135215
started this conversation in
Ideas
Replies: 1 comment
-
Yeah this would make a difference mostly in cases when there are many instances. For the high level api usecases I don't think it'll make a big difference. The ifcopenshell entity instances fully live in C++ and get their attribute lookups dynamically, so also there I don't see much to gain. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.
For example here
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/api/spatial/assign_container.py
Lines 24 to 25 in 7229f72
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.htmlBeta Was this translation helpful? Give feedback.
All reactions