[Python-Dev] PEP 0424: A method for exposing a length hint
Raymond Hettinger
raymond.hettinger at gmail.com
Thu Aug 2 17:43:38 CEST 2012
On Aug 1, 2012, at 1:46 AM, Mark Shannon wrote:
>> '''
> Being able to pre-allocate lists based on the expected size, as estimated by __length_hint__,
> can be a significant optimization.
> PyPy has been observed to run some code slower than CPython, purely because this optimization is absent.
> '''
>> Which is a PyPy bug report, not a rationale for a PEP ;)
Alex's rationale is correct and well expressed.
Your proposed revision reflects fuzzy thinking about why __length_hint__ is useful.
Regardless of resizing growth factors, it is *always* helpful to know how much
memory to allocate. Calls to the allocators (especially for large blocks)
and possible the recopying of data should be avoided when possible.
Raymond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120802/7c80a151/attachment.html>
More information about the Python-Dev
mailing list