<p dir="auto">Consider:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="using BenchmarkTools

struct Foo{T}
    x::T
end

const m = [1,2,3]
const k = 1:3

@btime Foo(k);
@btime Foo(m);"><pre class="notranslate"><code class="notranslate">using BenchmarkTools

struct Foo{T}
    x::T
end

const m = [1,2,3]
const k = 1:3

@btime Foo(k);
@btime Foo(m);
</code></pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; @btime Foo(k);

  0.029 ns (0 allocations: 0 bytes)

julia&gt; @btime Foo(m);
  4.952 ns (1 allocation: 16 bytes)"><pre class="notranslate"><code class="notranslate">julia&gt; @btime Foo(k);

  0.029 ns (0 allocations: 0 bytes)

julia&gt; @btime Foo(m);
  4.952 ns (1 allocation: 16 bytes)
</code></pre></div>
<p dir="auto">It doesn't seem like <code class="notranslate">Foo(m)</code> should allocate when <code class="notranslate">Foo(k)</code> can avoid it.</p>
<hr>
<p dir="auto">Add <code class="notranslate">sum_kbn(itr)</code> and <code class="notranslate">sum_kbn(f, itr)</code> methods.</p>
<p dir="auto"><a href="https://discourse.julialang.org/t/why-sum-kbn-cant-sum-generators/1717/2" rel="nofollow">https://discourse.julialang.org/t/why-sum-kbn-cant-sum-generators/1717/2</a></p>