# Performance and memory regression with function wrappers in Julia 1.4+

**URL:** <https://discourse.julialang.org/t/performance-and-memory-regression-with-function-wrappers-in-julia-1-4/44589>\
**Category:** General Usage\
**Created:** [August 8, 2020, 10:15pm UTC](https://discourse.julialang.org/t/performance-and-memory-regression-with-function-wrappers-in-julia-1-4/44589 "2020-08-08T22:15:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 8, 2020, 10:15pm UTC](https://discourse.julialang.org/t/performance-and-memory-regression-with-function-wrappers-in-julia-1-4/44589/1 "2020-08-08T22:15:55Z")

</div>

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-auto
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-auto
julia> @btime $w()
  5.435 ns (0 allocations: 0 bytes)

```

Julia 1.4.2:

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

```

Julia 1.5.0

```julia-auto
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.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 9, 2020, 12:55am UTC](https://discourse.julialang.org/t/performance-and-memory-regression-with-function-wrappers-in-julia-1-4/44589/2 "2020-08-09T00:55:49Z")

</div>

[https://github.com/yuyichao/FunctionWrappers.jl/issues/14](https://github.com/yuyichao/FunctionWrappers.jl/issues/14) base issue.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 9, 2020, 1:30am UTC](https://discourse.julialang.org/t/performance-and-memory-regression-with-function-wrappers-in-julia-1-4/44589/3 "2020-08-09T01:30:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 9, 2020, 3:08am UTC](https://discourse.julialang.org/t/performance-and-memory-regression-with-function-wrappers-in-julia-1-4/44589/4 "2020-08-09T03:08:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 9, 2020, 3:12am UTC](https://discourse.julialang.org/t/performance-and-memory-regression-with-function-wrappers-in-julia-1-4/44589/5 "2020-08-09T03:12:16Z")

</div>

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