# No allocs after restart

**URL:** <https://discourse.julialang.org/t/no-allocs-after-restart/117273>\
**Category:** New to Julia\
**Created:** [July 20, 2024, 1:34pm UTC](https://discourse.julialang.org/t/no-allocs-after-restart/117273 "2024-07-20T13:34:56Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 21, 2024, 4:51pm UTC](https://discourse.julialang.org/t/no-allocs-after-restart/117273/14 "2024-07-21T16:51:58Z")

</div>

> [@freeman](#):
>
> FunctionWrapper calls something called `do_ccall` which calls something called `macro expansion`

I think this is just showing it’s a [generated function](https://github.com/yuyichao/FunctionWrappers.jl/blob/3a579da1e5080d4563b6e819f88f4525aff4f45d/src/FunctionWrappers.jl#L100). Can’t really guess where the 10M allocations are from (over how many iterations?) without details. I do recall that it’s the `reinit_wrapper` call that gets flagged as a runtime dispatch by JET.jl, but that is only supposed to be run automatically at precompile-time, not at runtime.

Even less certain about this causing allocations, but worth saying that `reinit_wrapper` mutation is necessary to make even newly instantiated `FunctionWrapper`s respond to dynamic method changes. This isn’t documented or public but I spot no alternative in the source.

```julia
julia> using FunctionWrappers: FunctionWrappers as FWs, FunctionWrapper as FW

julia> foo() = 1; fwoo = FW{Int, Tuple{}}(foo);

julia> foo(), fwoo() # works as expected
(1, 1)

julia> foo() = 2; foo(), fwoo() # previous wrapper is obsolete
(2, 1)

julia> fwoo2 = FW{Int, Tuple{}}(foo); foo(), fwoo(), fwoo2() # new wrapper is obsolete
(2, 1, 1)

julia> FWs.reinit_wrapper(fwoo); foo(), fwoo(), fwoo2() # reinit_wrapper updates a wrapper
(2, 2, 1)

julia> foo() = 3; fwoo3 = FW{Int, Tuple{}}(foo); foo(), fwoo(), fwoo2(), fwoo3() # new wrapper is obsolete to 1st version
(3, 2, 1, 1)

```

---

_[View the full topic](https://discourse.julialang.org/t/no-allocs-after-restart/117273)._
