<p dir="auto">Lets say I define a tuple type with two members a,b</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="immutable TupleTest{A,B}
         a::A
         b::B
       end

tv = TupleTest(rand(3,3),rand(4,2))"><pre class="notranslate"><code class="notranslate">immutable TupleTest{A,B}
         a::A
         b::B
       end

tv = TupleTest(rand(3,3),rand(4,2))
</code></pre></div>
<p dir="auto">next, I also define a simple matrix</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tc = rand(4,2)"><pre class="notranslate"><code class="notranslate">tc = rand(4,2)
</code></pre></div>
<p dir="auto">such that <code class="notranslate">typeof(tc)</code> and  <code class="notranslate">typeof(tv.b)</code> give the same result.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="typeof(tc) == typeof(tv.b)
&gt; true"><pre class="notranslate"><code class="notranslate">typeof(tc) == typeof(tv.b)
&gt; true
</code></pre></div>
<p dir="auto">Now benchmarking them I get the following results:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@time for i in 1:10^6
       tv.b+tv.b*2.0;
       end
  0.215183 seconds (3.00 M allocations: 274.658 MB, 10.95% gc time)

@time for i in 1:10^6
       tc+tc*2.0;
       end
  0.179003 seconds (3.00 M allocations: 274.658 MB, 11.28% gc time)"><pre class="notranslate"><code class="notranslate">@time for i in 1:10^6
       tv.b+tv.b*2.0;
       end
  0.215183 seconds (3.00 M allocations: 274.658 MB, 10.95% gc time)

@time for i in 1:10^6
       tc+tc*2.0;
       end
  0.179003 seconds (3.00 M allocations: 274.658 MB, 11.28% gc time)
</code></pre></div>
<p dir="auto">The tuple type version is 15%-20% slower. Is this due to the overhead of using tuples and is that constant or does it grow with problem size ? I don't understand how tuple types work internally, but I read somewhere that there is no overhead if you are using the same concrete types in the computation. Does that statement apply here as-well ? Pardon me if this questions sounds naive, am trying to understand the reason for performance difference.</p>
<p dir="auto">Assuming that the overhead of using tuple types is constant, then if my computation within the loop is complex, the relative performance different should decrease, which will be nice...</p>
<p dir="auto">I am on Julia 0.4</p>
<p dir="auto">thanks,<br>
Nitin</p>
<p dir="auto">This keeps coming up, and rather than direct people to the performance tips, I feel like we should really just try to fix the issue. One relatively non-disruptive approach might be to emit code that accesses globals with a fast path that assumes that they have the same type that they currently have and a slow path that handles arbitrary type. A harder fix would be the compile-time version of that: generate code that assumes that globals retain their current type and invalidate it if the type changes. One might want to let compilation happen a couple of times before giving up and generating pessimistic general code.</p>
<p dir="auto">Related: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2354117" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/265" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/265/hovercard" href="https://github.com/JuliaLang/julia/issues/265">#265</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3501927" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/524" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/524/hovercard" href="https://github.com/JuliaLang/julia/issues/524">#524</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="5220583" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/964" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/964/hovercard" href="https://github.com/JuliaLang/julia/issues/964">#964</a></p>