stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
104 stars 27 forks source link

Using `__slots__` for classes? #2654

Closed oakleybrunt closed 2 months ago

oakleybrunt commented 2 months ago

It seems to me that we could be utilising the __slots__ attribute on classes to reduce attribute access time and save some memory. For most if not all classes, we are already sure of what attributes each class is going to have which means that using __slots__ to bypass use of a class __dict__ for attribute lookups would work well. For example, in the case of unique LFRic Kern classes, all of them must share the same attributes, so why not put them into __slots__? They can still be set and changed, they just won't live in a dictionary.

arporter commented 2 months ago

You'll have to give some context here @oakleybrunt - I don't know what __slots__ does/how one would use it. If it's just a performance thing then we probably don't care - the performance bottleneck is by far and away the code parsing performed by fparser.

oakleybrunt commented 2 months ago

You'll have to give some context here @oakleybrunt - I don't know what __slots__ does/how one would use it. If it's just a performance thing then we probably don't care - the performance bottleneck is by far and away the code parsing performed by fparser.

Ah, okay. If the performance bottleneck is the parsing, then this is not worth it.