[issue18305] [patch] Fast sum() for non-numbers

Sergey report at bugs.python.org
Tue Jul 16 04:07:55 CEST 2013


Sergey added the comment:

> This is not a common case. A common case is creating short tuples and keeping a lot of tuples in memory.

> For fast += you need keep not only a size of tuple, but also a size of allocated memory. It's a cause of sys.getsizeof([1, 2]) > sys.getsizeof((1, 2)).

Agree. But is it worth worrying about? How much RAM could be taken by it? E.g. python test uses ~30000 tuples in peak. So if we add e.g. 32 bytes to tuple then python test would use 106MB of RAM instead of 105MB. 1%? ;)

> You shouldn't optimize a rare case at the cost of regression in common usage.

This could optimize many cases, like instant tuple copy, or instant conversions of lists to tuples and back, if this idea is extended to lists. It may also work for strings.

----------

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


More information about the Python-bugs-list mailing list