3 ms·
> Yes, __slots__ is an optimization to reduce memory consumption, not to increase speed. It can increase speed though in practice. Less memory means less manag
by viraptor 6y ago
> Yes, __slots__ is an optimization to reduce memory consumption, not to increase speed.
It can increase speed though in practice. Less memory means less management and better cache usage. I've nearly doubled the speed of stream reconstruction from packet capture with a lot of slots usage. (Huge amount of tiny objects)
- pdonis 6y agoFor cases where you don't need to access any non-slot attributes (packet capture would generally be one of those cases), yes, __slots__ can speed things up as well.