diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2018-10-28 20:16:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-28 20:16:26 (GMT) |
commit | 372d705d958964289d762953d0a61622755f5386 (patch) | |
tree | f6a01b7f97739c53a8a99812ce690cbd7058588c /Misc | |
parent | 569d12f44847f18fc5b514b24e8ab901b0d96895 (diff) | |
download | cpython-372d705d958964289d762953d0a61622755f5386.zip cpython-372d705d958964289d762953d0a61622755f5386.tar.gz cpython-372d705d958964289d762953d0a61622755f5386.tar.bz2 |
bpo-33234 Improve list() pre-sizing for inputs with known lengths (GH-9846)
The list() constructor isn't taking full advantage of known input
lengths or length hints. This commit makes the constructor
pre-size and not over-allocate when the input size is known (the
input collection implements __len__). One on the main advantages is
that this provides 12% difference in memory savings due to the difference
between overallocating and allocating exactly the input size.
For efficiency purposes and to avoid a performance regression for small
generators and collections, the size of the input object is calculated using
__len__ and not __length_hint__, as the later is considerably slower.
Diffstat (limited to 'Misc')
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2018-04-17-01-24-51.bpo-33234.l9IDtp.rst | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-04-17-01-24-51.bpo-33234.l9IDtp.rst b/Misc/NEWS.d/next/Core and Builtins/2018-04-17-01-24-51.bpo-33234.l9IDtp.rst new file mode 100644 index 0000000..2f9cd62 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-04-17-01-24-51.bpo-33234.l9IDtp.rst @@ -0,0 +1,2 @@ +The list constructor will pre-size and not over-allocate when +the input lenght is known. |