title: What causes [*a] to overallocate?
body: <p>Apparently <code>list(a)</code> doesn't overallocate, <code>[x for x in a]</code> overallocates at some points, and <code>[*a]</code> overallocates <em>all the time</em>?</p>
  
  <p><a href="https://i.stack.imgur.com/SOZoe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SOZoe.png" alt="Sizes up to n=100"></a></p>
  
  <p>Here are sizes n from 0 to 12 and the resulting sizes in bytes for the three methods:</p>
  
  <pre><code>0 56 56 56
  1 64 88 88
  2 72 88 96
  3 80 88 104
  4 88 88 112
  5 96 120 120
  6 104 120 128
  7 112 120 136
  8 120 120 152
  9 128 184 184
  10 136 184 192
  11 144 184 200
  12 152 184 208
  </code></pre>
  
  <p>Computed like this, <a href="https://repl.it/repls/CoordinatedUnsungShockwave" rel="noreferrer">reproducable at repl.it</a>, using Python 3.<strong>8</strong>:</p>
  
  <pre><code>from sys import getsizeof
  
  for n in range(13):
      a = [None] * n
      print(n, getsizeof(list(a)),
               getsizeof([x for x in a]),
               getsizeof([*a]))
  </code></pre>
  
  <p><strong>So: How does this work?</strong> How does <code>[*a]</code> overallocate? Actually, what mechanism does it use to create the result list from the given input? Does it use an iterator over <code>a</code> and use something like <code>list.append</code>? Where is the source code?</p>
  
  <p>(<a href="https://colab.research.google.com/drive/1LOy2rb63wHZ2TSFrnoSlYXz1oOa1VkZ6" rel="noreferrer">Colab with data and code</a> that produced the images.)</p>
  
  <p>Zooming in to smaller n:</p>
  
  <p><a href="https://i.stack.imgur.com/7F3Ba.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7F3Ba.png" alt="Sizes up to n=40"></a></p>
  
  <p>Zooming out to larger n:</p>
  
  <p><a href="https://i.stack.imgur.com/xwhob.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xwhob.png" alt="Sizes up to n=1000"></a></p>