[issue33234] Improve list() pre-sizing for inputs with known lengths

Raymond Hettinger report at bugs.python.org
Thu Apr 5 17:46:53 EDT 2018


New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:

The list() constructor isn't taking full advantage of known input lengths or length hints.  Ideally, it should pre-size and not over-allocate when the input size is known or can be reasonably estimated.

Python 3.8.0a0 (heads/master:091e95e900, Apr  5 2018, 09:48:33)
[Clang 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from sys import getsizeof
>>> getsizeof([0] * 10)
144
>>> getsizeof(list([0] * 10))
200
>>> getsizeof(list(range(10)))
200

----------
components: Interpreter Core
messages: 315006
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Improve list() pre-sizing for inputs with known lengths
type: performance
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33234>
_______________________________________


More information about the Python-bugs-list mailing list