<p dir="auto">Is this confusing performance a bug? Version 1.3.1</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="img = rand(512,512,16)
@time mapslices(sum, img, dims=[3])
@time sum([img[:,:,i] for i=1:size(img)[3]])"><pre class="notranslate">img <span class="pl-k">=</span> <span class="pl-c1">rand</span>(<span class="pl-c1">512</span>,<span class="pl-c1">512</span>,<span class="pl-c1">16</span>)
<span class="pl-c1">@time</span> <span class="pl-c1">mapslices</span>(sum, img, dims<span class="pl-k">=</span>[<span class="pl-c1">3</span>])
<span class="pl-c1">@time</span> <span class="pl-c1">sum</span>([img[:,:,i] <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">size</span>(img)[<span class="pl-c1">3</span>]])</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  0.423263 seconds (2.89 M allocations: 74.065 MiB, 2.89% gc time)
  0.054033 seconds (53.06 k allocations: 64.729 MiB)"><pre class="notranslate"><code class="notranslate">  0.423263 seconds (2.89 M allocations: 74.065 MiB, 2.89% gc time)
  0.054033 seconds (53.06 k allocations: 64.729 MiB)
</code></pre></div>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; displaysize(stdout)
(17, 160)

julia&gt; displaysize(IOContext(stdout))
(17, 160)

julia&gt; sprint(; context=stdout) do io
           print(io, displaysize(io))
       end
&quot;(24, 80)&quot;"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">displaysize</span>(<span class="pl-c1">stdout</span>)
(<span class="pl-c1">17</span>, <span class="pl-c1">160</span>)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">displaysize</span>(<span class="pl-c1">IOContext</span>(<span class="pl-c1">stdout</span>))
(<span class="pl-c1">17</span>, <span class="pl-c1">160</span>)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">sprint</span>(; context<span class="pl-k">=</span><span class="pl-c1">stdout</span>) <span class="pl-k">do</span> io
           <span class="pl-c1">print</span>(io, <span class="pl-c1">displaysize</span>(io))
       <span class="pl-k">end</span>
<span class="pl-s"><span class="pl-pds">"</span>(24, 80)<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">Imo, the last one should be consistent with the others.</p>
<p dir="auto">Workaround:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; ioc = IOContext(stdout, :displaysize=&gt;displaysize(stdout));

julia&gt; sprint(; context=ioc) do io
           print(io, displaysize(io))
       end
&quot;(17, 160)&quot;"><pre class="notranslate">julia<span class="pl-k">&gt;</span> ioc <span class="pl-k">=</span> <span class="pl-c1">IOContext</span>(<span class="pl-c1">stdout</span>, <span class="pl-c1">:displaysize</span><span class="pl-k">=&gt;</span><span class="pl-c1">displaysize</span>(<span class="pl-c1">stdout</span>));

julia<span class="pl-k">&gt;</span> <span class="pl-c1">sprint</span>(; context<span class="pl-k">=</span>ioc) <span class="pl-k">do</span> io
           <span class="pl-c1">print</span>(io, <span class="pl-c1">displaysize</span>(io))
       <span class="pl-k">end</span>
<span class="pl-s"><span class="pl-pds">"</span>(17, 160)<span class="pl-pds">"</span></span></pre></div>