<p dir="auto">A call to <code class="notranslate">mapslices</code> that takes a <code class="notranslate">dims</code> argument is type unstable. This is the case in all recent versions of Julia (1.1.1, 1.2.0, 1.3.1, 1.4.2).</p>
<p dir="auto">For example:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="d = rand(10)
mapslices(identity, d; dims=1)"><pre class="notranslate">d <span class="pl-k">=</span> <span class="pl-c1">rand</span>(<span class="pl-c1">10</span>)
<span class="pl-c1">mapslices</span>(identity, d; dims<span class="pl-k">=</span><span class="pl-c1">1</span>)</pre></div>
<p dir="auto">Shows the following with <code class="notranslate">@code_warntype</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Variables
  #unused#::Core.Compiler.Const(getfield(Base, Symbol(&quot;#kw##mapslices&quot;))(), false)
  @_2::NamedTuple{(:dims,),Tuple{Int64}}
  @_3::Core.Compiler.Const(mapslices, false)
  f::Core.Compiler.Const(identity, false)
  A::Array{Float64,1}
  dims::Int64
  @_7::Int64

Body::Any
1 ─ %1  = Base.haskey(@_2, :dims)::Core.Compiler.Const(true, false)
│         %1
│         (@_7 = Base.getindex(@_2, :dims))
└──       goto #3
2 ─       Core.Compiler.Const(:(Core.UndefKeywordError(:dims)), false)
└──       Core.Compiler.Const(:(@_7 = Core.throw(%5)), false)
3 ┄       (dims = @_7)
│   %8  = (:dims,)::Core.Compiler.Const((:dims,), false)
│   %9  = Core.apply_type(Core.NamedTuple, %8)::Core.Compiler.Const(NamedTuple{(:dims,),T} where T&lt;:Tuple, false)
│   %10 = Base.structdiff(@_2, %9)::Core.Compiler.Const(NamedTuple(), false)
│   %11 = Base.pairs(%10)::Core.Compiler.Const(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}(), false)
│   %12 = Base.isempty(%11)::Core.Compiler.Const(true, false)
│         %12
└──       goto #5
4 ─       Core.Compiler.Const(:(Base.kwerr(@_2, @_3, f, A)), false)
5 ┄ %16 = Base.:(#mapslices#111)(dims, @_3, f, A)::Any
└──       return %16
"><pre class="notranslate"><code class="notranslate">Variables
  #unused#::Core.Compiler.Const(getfield(Base, Symbol("#kw##mapslices"))(), false)
  @_2::NamedTuple{(:dims,),Tuple{Int64}}
  @_3::Core.Compiler.Const(mapslices, false)
  f::Core.Compiler.Const(identity, false)
  A::Array{Float64,1}
  dims::Int64
  @_7::Int64

Body::Any
1 ─ %1  = Base.haskey(@_2, :dims)::Core.Compiler.Const(true, false)
│         %1
│         (@_7 = Base.getindex(@_2, :dims))
└──       goto #3
2 ─       Core.Compiler.Const(:(Core.UndefKeywordError(:dims)), false)
└──       Core.Compiler.Const(:(@_7 = Core.throw(%5)), false)
3 ┄       (dims = @_7)
│   %8  = (:dims,)::Core.Compiler.Const((:dims,), false)
│   %9  = Core.apply_type(Core.NamedTuple, %8)::Core.Compiler.Const(NamedTuple{(:dims,),T} where T&lt;:Tuple, false)
│   %10 = Base.structdiff(@_2, %9)::Core.Compiler.Const(NamedTuple(), false)
│   %11 = Base.pairs(%10)::Core.Compiler.Const(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}(), false)
│   %12 = Base.isempty(%11)::Core.Compiler.Const(true, false)
│         %12
└──       goto #5
4 ─       Core.Compiler.Const(:(Base.kwerr(@_2, @_3, f, A)), false)
5 ┄ %16 = Base.:(#mapslices#111)(dims, @_3, f, A)::Any
└──       return %16

</code></pre></div>
<p dir="auto">Due to this type instability, things like <a href="https://github.com/JuliaLang/Statistics.jl/issues/39"><code class="notranslate">Statistics.median(d; dims=n)</code> are also type unstable</a>.</p>
<p dir="auto">Consider the following piece of code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="n=10^6;
X = randn(1,n);
V(x) = 0.5 * dot(x,x);
f(V, X) = [ V((@view X[:,n])) for n = 1:size(X,2) ]"><pre class="notranslate"><code class="notranslate">n=10^6;
X = randn(1,n);
V(x) = 0.5 * dot(x,x);
f(V, X) = [ V((@view X[:,n])) for n = 1:size(X,2) ]
</code></pre></div>
<p dir="auto">Timing on this reveals:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; @time mapslices(V, X, 1);
  1.177690 seconds (12.00 M allocations: 267.024 MiB, 6.91% gc time)
julia&gt; @time f(V,X);
  0.047745 seconds (1.00 M allocations: 53.406 MiB, 5.58% gc time)"><pre class="notranslate"><code class="notranslate">julia&gt; @time mapslices(V, X, 1);
  1.177690 seconds (12.00 M allocations: 267.024 MiB, 6.91% gc time)
julia&gt; @time f(V,X);
  0.047745 seconds (1.00 M allocations: 53.406 MiB, 5.58% gc time)
</code></pre></div>
<p dir="auto">which is substantially different.</p>
<p dir="auto">Note that in this simple example, my data could be a column vector; however, this is a surrogate for problems where I have time series data and <code class="notranslate">X</code> is  d x n with 1&lt; d &lt;&lt; n.</p>