<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function f(a, b)
    for i = 1:1000000
        size(a) == size(b)
    end
end

julia&gt; @time f([1], [1])
elapsed time: 0.096288154 seconds (48000208 bytes allocated, 47.00% gc time)"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">f</span>(a, b)
    <span class="pl-k">for</span> i <span class="pl-k">=</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">1000000</span>
        <span class="pl-c1">size</span>(a) <span class="pl-k">==</span> <span class="pl-c1">size</span>(b)
    <span class="pl-k">end</span>
<span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@time</span> <span class="pl-c1">f</span>([<span class="pl-c1">1</span>], [<span class="pl-c1">1</span>])
elapsed time<span class="pl-k">:</span> <span class="pl-c1">0.096288154</span> seconds (<span class="pl-c1">48000208</span> bytes allocated, <span class="pl-c1">47.00</span><span class="pl-k">%</span> gc time)</pre></div>
<p dir="auto">This does not affect tuples in general:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function f(a, b)
    for i = 1:1000000
        a == b
    end
end

julia&gt; @time f((1,), (1,))
elapsed time: 0.002870282 seconds (128 bytes allocated)"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">f</span>(a, b)
    <span class="pl-k">for</span> i <span class="pl-k">=</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">1000000</span>
        a <span class="pl-k">==</span> b
    <span class="pl-k">end</span>
<span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@time</span> <span class="pl-c1">f</span>((<span class="pl-c1">1</span>,), (<span class="pl-c1">1</span>,))
elapsed time<span class="pl-k">:</span> <span class="pl-c1">0.002870282</span> seconds (<span class="pl-c1">128</span> bytes allocated)</pre></div>
<p dir="auto">This hurts <code class="notranslate">==</code> for arrays, which checks equality of sizes before proceeding, as well as in-place functions that need to check that the output is the same size as the input.</p>
<p dir="auto">Hi all,</p>
<p dir="auto">The following code seems to allocate a lot of memory:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function test!(arr::Array{(Int, Int)})
    for i = 1:10_000_000
        arr[1] = arr[2]
    end
end

a = [(1, 1), (2, 2)]
test!(a)"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">test!</span>(arr<span class="pl-k">::</span><span class="pl-c1">Array{(Int, Int)}</span>)
    <span class="pl-k">for</span> i <span class="pl-k">=</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">10_000_000</span>
        arr[<span class="pl-c1">1</span>] <span class="pl-k">=</span> arr[<span class="pl-c1">2</span>]
    <span class="pl-k">end</span>
<span class="pl-k">end</span>

a <span class="pl-k">=</span> [(<span class="pl-c1">1</span>, <span class="pl-c1">1</span>), (<span class="pl-c1">2</span>, <span class="pl-c1">2</span>)]
<span class="pl-c1">test!</span>(a)</pre></div>
<p dir="auto">Here are the results of <code class="notranslate">@time test!(a)</code> (using HEAD on the master branch, commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/JuliaLang/julia/commit/ce29d785098564b61af0c65113595b1af7ba0acb/hovercard" href="https://github.com/JuliaLang/julia/commit/ce29d785098564b61af0c65113595b1af7ba0acb"><tt>ce29d78</tt></a>) :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="elapsed time: 0.439144953 seconds (320013808 bytes allocated, 40.35% gc time)"><pre class="notranslate"><code class="notranslate">elapsed time: 0.439144953 seconds (320013808 bytes allocated, 40.35% gc time)
</code></pre></div>
<p dir="auto">On the other hand, using a composite type works as expected:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="immutable Pair{T1, T2}
  a::T1
  b::T2
end

function test!(arr::Array{Pair{Int, Int}})
    for i = 1:10_000_000
        arr[1] = arr[2]
    end
end

a = [Pair(1, 1), Pair(2, 2)]
test!(a)"><pre class="notranslate"><code class="notranslate">immutable Pair{T1, T2}
  a::T1
  b::T2
end

function test!(arr::Array{Pair{Int, Int}})
    for i = 1:10_000_000
        arr[1] = arr[2]
    end
end

a = [Pair(1, 1), Pair(2, 2)]
test!(a)
</code></pre></div>
<p dir="auto">Here <code class="notranslate">@time test!(a)</code> yields</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="elapsed time: 0.022649237 seconds (80 bytes allocated)"><pre class="notranslate"><code class="notranslate">elapsed time: 0.022649237 seconds (80 bytes allocated)
</code></pre></div>
<p dir="auto">Am I missing something obvious? It seems that each assignment triggers an allocation in the case of tuples (adding <code class="notranslate">@time</code> before the assignment suggests a 32 bytes allocation). Why is that? Is this documented somewhere?</p>
<p dir="auto">(I ran into this problem when trying to use a heap to extract the top <code class="notranslate">n</code> elements from a list of tuples without sorting it first, as done in Python's <code class="notranslate">heapq.nlargest</code> method)</p>