Python does not eliminate the overhead of such structures. I'm sorry. Its dynamic nature such compiler optimizations are complex. But then I do not know a single language that would eliminate the overhead associated with the maintenance of things in dictionaries.
dict (without owner) probably includes all the dictionaries that you create inside your object. They are marked as non-owners because they are not dictionaries for object instances.
What can you do:
Use __slots__ if you add __slots__ = ('the','names','of','fields') as an attribute of the class, python will use a more efficient implementation of the class. He will get rid of the dictionary used to store attributes.
If your dictionaries can be rewritten to use lists that will improve the situation. Lists are more memory efficient than dictionaries.
For best performance, you should remake your system to use numpy arrays. Each attribute of your class will become an array of size 256 * 256. In this case, each element will be stored very efficiently in space.
Alternatively, you can check out PyPy. It provides an alternative python implementation with JIT, as well as various time / space optimizations that may help.
sys.getsizeof does not say what you think of its reports. sys.getsizeof(myobj.Container) reports the size of the class object, not the size of the actual container objects. You want sys.getsizeof(myobj.Container()) or the like. Even this is not so accurate, because there is nothing in it except the base object. It does not account for a dictionary containing attributes. It will only report the size of the third row in your report.
source share