[issue33234] Improve list() pre-sizing for inputs with known lengths
Serhiy Storchaka
report at bugs.python.org
Tue Apr 17 16:32:06 EDT 2018
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
Calling PyObject_LengthHint() adds an overhead. It is significant for short sequences. I work on a patch that reduces it. PR 6493 adds the second call of PyObject_LengthHint() and increases the overhead.
As for this issue, in-place repeat overallocates too.
>>> a = [0]; a *= 10; getsizeof(a)
200
I think it would be better to make it not preallocating.
And maybe it would be worth to avoid overallocating if newsize > allocated + allocated/8 or something like.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33234>
_______________________________________
More information about the Python-bugs-list
mailing list