• Kevin Modzelewski's avatar
    Add new "SINGLETON" hidden class type · 4ca839f9
    Kevin Modzelewski authored
    The storage strategy per-object is the same as NORMAL, but instead of having
    immutable chains of hidden classes so that we can share them between instances,
    a SINGLETON hcls is unique to the single object that it is for.  This means
    that it can be mutable.
    
    This has the advantage that we don't have to track all the parents
    of the hidden class.  This is especially helpful since the cases that
    it's used for (Python classes and modules) tend to have a large number
    of attributes (>100 not uncommon).
    
    We could also use the DICT_BACKED strategy for those cases, but compared to
    DICT_BACKED, SINGLETON should have much better lookup performance since
    it is patchpoint-compatible.  Adding new attributes is probably slower,
    and deleting attributes is probably much slower, but I think those are
    hopefully rare.
    
    This cuts non-jit 'import pip' memory by 15%, from 113MB to 98MB.
    4ca839f9
typeobject.cpp 99.6 KB