[issue4998] __slots__ on Fraction is useless

Mark Dickinson report at bugs.python.org
Tue Jan 20 18:52:40 CET 2009


Mark Dickinson <dickinsm at gmail.com> added the comment:

A random data point:  just for fun, I just tried assessing the impact of 
__slots__ on Decimal instances, by the crude method of putting all of the 
Decimal instances that are created during a complete run of the Decimal 
test suite (over 100000 of them) into a list and watching memory usage.  
This was on a non-debug 32-bit build of py3k, with 16-bit Py_UNICODE 
(which is relevant because the coefficients of Decimal instances are 
strings).

Results: (*)

~44 bytes per Decimal on average with __slots__
~183 bytes per Decimal on average without __slots__

The effect on speed wasn't really significant:  removing __slots__ gives
at worst a 1-2% slowdown on a complete run of the test-suite.

So please let's not remove __slots__ from Fraction!



(*) raw numbers: 120343 total number of Decimals.  The following
are memory readings from the RSIZE column of top.

with __slots__:
    putting 8 copies of each Decimal into list -> 33M total usage
    putting 4 copies of each Decimal into list -> 55M total usage
without __slots__:
    putting 8 copies of each Decimal into list -> 182M total usage
    putting 4 copies of each Decimal into list -> 96M total usage.

I took the liberty of subtracting 4 bytes per list entry, to compensate
for the memory taken by the list itself.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4998>
_______________________________________


More information about the Python-bugs-list mailing list