I was surprised to find that FunctionWrapper
s 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.