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

Sergey report at bugs.python.org
Sun Jul 14 16:49:11 CEST 2013


Sergey added the comment:

> I guess such implementation of tuple will increase memory usage
> and creation time which are critical important for tuples.

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".

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.

This idea can be improved in many ways. For example it's possible to implement __add__ in C so that it would require no additional memory at all. But it is just a proof of concept, and I was trying to keep it simple, so the idea was easier to understand.

----------

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


More information about the Python-bugs-list mailing list