<p dir="auto"><code class="notranslate">sum(skipmissing(x))</code> is reasonably fast, but since <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="333568119" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/27651" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/27651/hovercard" href="https://github.com/JuliaLang/julia/pull/27651">#27651</a> a naive implementation of <code class="notranslate">sum</code> is even faster (up to 5×). This is particularly clear when the input array does contain missing values, probably because the naive sum uses masked SIMD instructions while <code class="notranslate">skipmissing</code> relies on branching (and the presence of missing values kills prediction).</p>
<p dir="auto">I haven't investigated this deeply, but IIUC <code class="notranslate">sum(skipmissing(x))</code> dispatches to <code class="notranslate">mapfoldl</code>, which uses the iteration protocol to go over the input. This means we lose the benefit of <code class="notranslate">@inbounds</code> and of <code class="notranslate">@simd</code>. Maybe something like <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="328740892" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/27384" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/27384/hovercard" href="https://github.com/JuliaLang/julia/issues/27384">#27384</a> would help with <code class="notranslate">@inbounds</code> at least?</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function mysum(X)
   s = zero(eltype(X))
   @inbounds @simd for x in X
       if x !== missing
           s += x
       end
   end
   s
end

# With Vector{Int}
X1 = rand(Int, 10_000_000);
X2 = Vector{Union{Missing,Int}}(X1);
X3 = ifelse.(rand(length(X2)) .&lt; 0.9, X2, missing);

julia&gt; @btime mysum(X1);
 5.594 ms (1 allocation: 16 bytes)

julia&gt; @btime mysum(X2);
 5.791 ms (1 allocation: 16 bytes)

julia&gt; @btime mysum(X3);
 5.681 ms (1 allocation: 16 bytes)

julia&gt; @btime sum(skipmissing(X1));
 7.316 ms (2 allocations: 32 bytes)

julia&gt; @btime sum(skipmissing(X2));
 18.175 ms (2 allocations: 32 bytes)

julia&gt; @btime sum(skipmissing(X3));
 28.240 ms (2 allocations: 32 bytes)

# With Vector{Float64}
Y1 = rand(Float64, 10_000_000);
Y2 = Vector{Union{Missing,Float64}}(Y1);
Y3 = ifelse.(rand(length(Y2)) .&lt; 0.9, Y2, missing);

julia&gt; @btime mysum(Y1);
 5.860 ms (1 allocation: 16 bytes)

julia&gt; @btime mysum(Y2);
 13.849 ms (1 allocation: 16 bytes)

julia&gt; @btime mysum(Y3);
 17.428 ms (1 allocation: 16 bytes)

julia&gt; @btime sum(skipmissing(Y1));
 13.816 ms (2 allocations: 32 bytes)

julia&gt; @btime sum(skipmissing(Y2));
 18.254 ms (2 allocations: 32 bytes)

julia&gt; @btime sum(skipmissing(Y3));
 28.430 ms (2 allocations: 32 bytes)
"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">mysum</span>(X)
   s <span class="pl-k">=</span> <span class="pl-c1">zero</span>(<span class="pl-c1">eltype</span>(X))
   <span class="pl-c1">@inbounds</span> <span class="pl-c1">@simd</span> <span class="pl-k">for</span> x <span class="pl-k">in</span> X
       <span class="pl-k">if</span> x <span class="pl-k">!==</span> <span class="pl-c1">missing</span>
           s <span class="pl-k">+=</span> x
       <span class="pl-k">end</span>
   <span class="pl-k">end</span>
   s
<span class="pl-k">end</span>

<span class="pl-c"><span class="pl-c">#</span> With Vector{Int}</span>
X1 <span class="pl-k">=</span> <span class="pl-c1">rand</span>(Int, <span class="pl-c1">10_000_000</span>);
X2 <span class="pl-k">=</span> <span class="pl-c1">Vector</span><span class="pl-c1">{Union{Missing,Int}}</span>(X1);
X3 <span class="pl-k">=</span> <span class="pl-c1">ifelse</span>.(<span class="pl-c1">rand</span>(<span class="pl-c1">length</span>(X2)) <span class="pl-k">.&lt;</span> <span class="pl-c1">0.9</span>, X2, <span class="pl-c1">missing</span>);

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">mysum</span>(X1);
 <span class="pl-c1">5.594</span> ms (<span class="pl-c1">1</span> allocation<span class="pl-k">:</span> <span class="pl-c1">16</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">mysum</span>(X2);
 <span class="pl-c1">5.791</span> ms (<span class="pl-c1">1</span> allocation<span class="pl-k">:</span> <span class="pl-c1">16</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">mysum</span>(X3);
 <span class="pl-c1">5.681</span> ms (<span class="pl-c1">1</span> allocation<span class="pl-k">:</span> <span class="pl-c1">16</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">sum</span>(<span class="pl-c1">skipmissing</span>(X1));
 <span class="pl-c1">7.316</span> ms (<span class="pl-c1">2</span> allocations<span class="pl-k">:</span> <span class="pl-c1">32</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">sum</span>(<span class="pl-c1">skipmissing</span>(X2));
 <span class="pl-c1">18.175</span> ms (<span class="pl-c1">2</span> allocations<span class="pl-k">:</span> <span class="pl-c1">32</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">sum</span>(<span class="pl-c1">skipmissing</span>(X3));
 <span class="pl-c1">28.240</span> ms (<span class="pl-c1">2</span> allocations<span class="pl-k">:</span> <span class="pl-c1">32</span> bytes)

<span class="pl-c"><span class="pl-c">#</span> With Vector{Float64}</span>
Y1 <span class="pl-k">=</span> <span class="pl-c1">rand</span>(Float64, <span class="pl-c1">10_000_000</span>);
Y2 <span class="pl-k">=</span> <span class="pl-c1">Vector</span><span class="pl-c1">{Union{Missing,Float64}}</span>(Y1);
Y3 <span class="pl-k">=</span> <span class="pl-c1">ifelse</span>.(<span class="pl-c1">rand</span>(<span class="pl-c1">length</span>(Y2)) <span class="pl-k">.&lt;</span> <span class="pl-c1">0.9</span>, Y2, <span class="pl-c1">missing</span>);

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">mysum</span>(Y1);
 <span class="pl-c1">5.860</span> ms (<span class="pl-c1">1</span> allocation<span class="pl-k">:</span> <span class="pl-c1">16</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">mysum</span>(Y2);
 <span class="pl-c1">13.849</span> ms (<span class="pl-c1">1</span> allocation<span class="pl-k">:</span> <span class="pl-c1">16</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">mysum</span>(Y3);
 <span class="pl-c1">17.428</span> ms (<span class="pl-c1">1</span> allocation<span class="pl-k">:</span> <span class="pl-c1">16</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">sum</span>(<span class="pl-c1">skipmissing</span>(Y1));
 <span class="pl-c1">13.816</span> ms (<span class="pl-c1">2</span> allocations<span class="pl-k">:</span> <span class="pl-c1">32</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">sum</span>(<span class="pl-c1">skipmissing</span>(Y2));
 <span class="pl-c1">18.254</span> ms (<span class="pl-c1">2</span> allocations<span class="pl-k">:</span> <span class="pl-c1">32</span> bytes)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">sum</span>(<span class="pl-c1">skipmissing</span>(Y3));
 <span class="pl-c1">28.430</span> ms (<span class="pl-c1">2</span> allocations<span class="pl-k">:</span> <span class="pl-c1">32</span> bytes)
</pre></div>
<p dir="auto">Unfortunately, the impressive speed boosts that were made for Julia on Linux seem to have been lost in translation. On the same machine, I get ~0.6 secs on Linux vs. ~6 on Windows.</p>