Skip to content

mean's dims argument is specializing as ::Function instead of ::Colon #37

@mbauman

Description

@mbauman

We use the : throughout as a sentinel for "all dimensions." We do not typically call it as a function in this use case, even though Colon <: Function.

However, I think this means that it's getting the specialization rules for Functions and thus no longer specializing as it was previously expected to. In particular, this is introducing type-instabilities that are slowing down basic functions like mean:

#### master (b72e191ea9) ####
julia> using Statistics, BenchmarkTools

julia> @benchmark mean($(zeros(10)))
BenchmarkTools.Trial:
  memory estimate:  16 bytes
  allocs estimate:  1
  --------------
  minimum time:     11.117 ns (0.00% GC)
  median time:      11.449 ns (0.00% GC)
  mean time:        13.226 ns (1.25% GC)
  maximum time:     635.868 ns (96.44% GC)
  --------------
  samples:          10000
  evals/sample:     998

#### 1.4.0 ####
julia> @benchmark mean($(zeros(10)))
BenchmarkTools.Trial:
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     4.453 ns (0.00% GC)
  median time:      5.994 ns (0.00% GC)
  mean time:        5.884 ns (0.00% GC)
  maximum time:     37.309 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1000

(I originally thought this was a Cthulhu bug, but it does appear that @descend is properly showing me how Julia is specializing this: JuliaDebug/Cthulhu.jl#77)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions