[issue18305] [patch] Fast sum() for non-numbers
Serhiy Storchaka
report at bugs.python.org
Mon Jul 15 10:11:00 CEST 2013
Serhiy Storchaka added the comment:
> On the contrary, it will reduce memory usage and creation time compared to regular tuples, because in cases like:
> c = a + b
> you do not have to spend time and memory for allocating and copying elements of "a".
This is not a common case. A common case is creating short tuples and keeping a lot of tuples in memory.
> The only case when it could use more memory is if you explicitly delete "c" after that operation. But this can be solved too, internal storage can be resized to a smaller value when its tail elements are not used any more.
No. For fast += you need keep not only a size of tuple, but also a size of of allocated memory. It's a cause of sys.getsizeof([1, 2]) > sys.getsizeof((1, 2)).
For fast + you need even more complicated internal structure.
Tuples should be compact and fast. You shouldn't optimize a rare case at the cost of regression in common usage.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18305>
_______________________________________
More information about the Python-bugs-list
mailing list