title: Julia NTuple of Union takes exponential time/memory to compile?
body: <p>I was making a relatively large NTuple where the values could sometimes be nothing. I noticed it was taking forever to build my structs. Looking closer, it seems NTuple takes exponential time and RAM to build. Why is this?</p>
  
  <p>Does</p>
  
  <pre><code>NTuple{2, Union{Int8, Nothing}}
  </code></pre>
  
  <p>get lowered to</p>
  
  <pre><code>Union{Tuple{Int8, Int8}, Tuple{Int8, Nothing}, Tuple{Nothing, Int8}, Tuple{Nothing, Nothing}}`
  </code></pre>
  
  <p>?</p>
  
  <p>If so, why?</p>
  
  <p>For reference, some timing:</p>
  
  <pre><code>julia&gt; for i in 1:100
           @time NTuple{i, Union{Int8, Nothing}}(Tuple(1:i))
         end
    0.006849 seconds (11.18 k allocations: 551.179 KiB)
    0.010944 seconds (19.20 k allocations: 925.659 KiB)
    0.010264 seconds (23.84 k allocations: 1.090 MiB)
    0.011766 seconds (29.47 k allocations: 1.351 MiB)
    0.012595 seconds (34.73 k allocations: 1.566 MiB)
    0.014412 seconds (40.18 k allocations: 1.795 MiB)
    0.017048 seconds (47.26 k allocations: 2.096 MiB)
    0.019018 seconds (57.91 k allocations: 2.559 MiB)
    0.029885 seconds (76.22 k allocations: 3.373 MiB, 14.82% gc time)
    0.056189 seconds (111.05 k allocations: 4.945 MiB)
    0.063619 seconds (181.21 k allocations: 8.135 MiB)
    0.112901 seconds (326.06 k allocations: 14.735 MiB, 2.65% gc time)
    0.215413 seconds (631.22 k allocations: 28.683 MiB, 0.92% gc time)
    0.442667 seconds (1.27 M allocations: 58.127 MiB, 1.08% gc time)
    0.950875 seconds (2.63 M allocations: 120.167 MiB, 0.85% gc time)
    2.064045 seconds (5.55 M allocations: 254.885 MiB, 0.90% gc time)
    4.472772 seconds (11.62 M allocations: 533.487 MiB, 0.74% gc time)
    9.727991 seconds (24.34 M allocations: 1.091 GiB, 0.73% gc time)
   22.080309 seconds (50.95 M allocations: 2.285 GiB, 0.63% gc time)
   48.423639 seconds (106.53 M allocations: 4.777 GiB, 0.76% gc time)
   90.654842 seconds (222.40 M allocations: 9.973 GiB, 0.78% gc time)
  </code></pre>