I am creating a Python class to represent a Geographic Position. Its main goal is to store latitude, longitude, elevation
, so it is going to be used much like a C# "struct", a value type that is supposed to have lots of instances at runtime.
I am considering adding some methods to that class (__str__
would be one), and I wonder if adding methods to a class has any impact on the performance.
Performance metrics I am interested on are the following:
- Object creation overhead;
- Memory overhead (when lots of instances are created)
- Speed of manipulation of the class even when the "extra methods" are not called.
For example, I read that __slots__
is useful in some contexts because by default the __dict__
attribute ends up eating some space on each instance.
So que question is:
Which impacts are supposed to exist if I have a class with a large amount of methods?
Or pragmatically speaking:
Is adding more and more methods to a class that is supposed to be lightweight something I should try to avoid for any reason?