On Mon, Jul 16, 2012 at 11:02 AM, Stefan Behnel <span dir="ltr"><<a href="mailto:stefan_ml@behnel.de" target="_blank">stefan_ml@behnel.de</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Mark Shannon, 16.07.2012 10:37:<br>
<div class="im">> If resizing of lists is too slow, then we should reconsider the 9/8 factor<br>
> and/or look to tweak the resizing code.<br>
<br>
</div>The thing is that the performance is platform specific. On systems with a<br>
fast memory allocator, especially on Linux, the difference is negligible.<br>
However, with a slow memory allocator, especially a slow realloc(), e.g. on<br>
Windows or Solaris, this can substantially hurt the performance, up to a<br>
quadratically increasing runtime in the worst case.<br>
<br>
The length hint was implemented specifically to work around this problem.<br>
<span class="HOEnZb"><font color="#888888"><br>
Stefan<br>
</font></span><div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div> </div><div>It's not the actual allocation (typically), it's the copying that's the problem.</div><div><br></div><div>As far as data goes - preallocation can make 4x difference (on PyPy, although the dominant operation is not different on CPython) on ''.join(some-iterable). It depends grossly on the sizes of the list, so you can't claim that there is a precise speedup of a constant factor, however, there are cases where it *can* be significant (as in the copying is by far the dominating operation), most notable giant templates with iterators written in C.</div>
<div><br></div><div>Speaking of which - I find this bikeshed disgusting. The purpose of the PEP is to codify whatever is already written in code in CPython. If you guys don't want it, we'll just implement it anyway and try to follow the CPython current implementation from 2.7.</div>
<div><br></div><div>Cheers,</div><div>fijal</div></div>