[Python-Dev] Accepting PEP 560 -- Core support for typing module and generic types

Serhiy Storchaka storchaka at gmail.com
Fri Dec 15 03:03:32 EST 2017


15.12.17 02:33, Antoine Pitrou пише:
> On Thu, 14 Dec 2017 16:03:48 -0800
> Guido van Rossum <guido at python.org> wrote:
>> A slot is pretty expensive, as *every* class in existence will be another 8
>> bytes larger (and possibly more due to malloc rounding).
> 
> I'm always surprised by the discussions about class object size.
> Even imagining you have 10000 classes in memory (a pretty large number,
> though I'm sure you can reach that number with a lot of dependencies),
> we're talking about a total 800 kB memory growth (let's recall that
> each of those classes will probably have code objects, docstrings and what
> not attached to it -- i.e. you don't often create empty classes).
> 
> Is it really an important concern?

The increased memory consumption is not the only cost. Initializing new 
slots takes a time. You have to spent a time for all class objects, not 
only for theses that have correspondent methods. In case of complex 
hierarchy the cost is larger, because you need to look up methods in all 
parent classes. This increases the startup time and increases the cost 
of creating local classes.



More information about the Python-Dev mailing list