Performance and memory regression with function wrappers in Julia 1.4+

I was surprised to find that FunctionWrappers which return a closed-over value appear to be significantly slower and allocate memory in Julia 1.4 and 1.5, while they are faster and allocate no memory in Julia 1-1.3:

Setup:

julia> using BenchmarkTools

julia> using FunctionWrappers: FunctionWrapper

julia> w = let closed_over=([1], [2])
         FunctionWrapper{typeof(closed_over), Tuple{}}(() -> closed_over)
       end;

Results

Julia 1.3.1:

julia> @btime $w()
  5.435 ns (0 allocations: 0 bytes)

Julia 1.4.2:

julia> @btime $w()
  9.919 ns (1 allocation: 16 bytes)

Julia 1.5.0

julia> @btime $w()
  10.112 ns (1 allocation: 32 bytes)

This turns out to be the source of a significant performance regression in Parametron.jl (which was designed to allocate zero memory).

I’ll open a github issue soon unless anyone has any suggestions here.

https://github.com/yuyichao/FunctionWrappers.jl/issues/14 base issue.

Thanks–do you know if there’s an open issue in Base for this? I don’t see one linked from the FunctionWrappers.jl github issue. I’ll create one if not.

I thought so… but since there was no link I m not sure…

I’ve opened one here: https://github.com/JuliaLang/julia/issues/36977

1 Like