Hacker News new | ask | show | jobs
by lunixbochs 1992 days ago
As this doesn't use `__slots__`, every empty Array() will be 176 bytes vs the 56 bytes of [], and incur a dict allocation per array.

This is due to classes without `__slots__` gaining a `__dict__` attribute for dynamic attribute assignment.

Currently:

    >>> sys.getsizeof([])
    56

    >>> a = Array()
    >>> sys.getsizeof(a)
    72
    >>> sys.getsizeof(a.__dict__)
    104
with `__slots__ = []` in the Array class definition:

    >>> a = Array()
    >>> sys.getsizeof(a)
    56
    >>> sys.getsizeof(a.__dict__)
    AttributeError: 'Array' object has no attribute '__dict__'