diff --git a/base/missing.jl b/base/missing.jl index 4a13586e3654d0..38322bee65b1e2 100644 --- a/base/missing.jl +++ b/base/missing.jl @@ -190,7 +190,10 @@ function iterate(itr::SkipMissing, state...) end # Optimized mapreduce implementation -mapreduce(f, op, itr::SkipMissing{<:AbstractArray}) = _mapreduce(f, op, IndexStyle(itr.x), itr) +# The generic method is faster when !(eltype(A) >: Missing) since it does not need +# additional loops to identify the two first non-missing values of each block +mapreduce(f, op, itr::SkipMissing{<:AbstractArray}) = + _mapreduce(f, op, IndexStyle(itr.x), eltype(itr.x) >: Missing ? itr : itr.x) function _mapreduce(f, op, ::IndexLinear, itr::SkipMissing{<:AbstractArray}) A = itr.x