# Does inlining work when the function is passed as an argument?

**URL:** <https://discourse.julialang.org/t/does-inlining-work-when-the-function-is-passed-as-an-argument/34470>\
**Category:** Performance\
**Created:** [February 11, 2020, 2:57pm UTC](https://discourse.julialang.org/t/does-inlining-work-when-the-function-is-passed-as-an-argument/34470 "2020-02-11T14:57:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [February 11, 2020, 2:57pm UTC](https://discourse.julialang.org/t/does-inlining-work-when-the-function-is-passed-as-an-argument/34470/1 "2020-02-11T14:57:39Z")

</div>

Just wondering. For example

```julia
@inline function foo(x,y)
    @assert length(x) == length(y)
    x .+ y.*rand(length(y))
end

function apply_function(x,y,f)
    f(x,y)
end

julia> apply_function(rand(10), rand(10), foo)

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 11, 2020, 3:20pm UTC](https://discourse.julialang.org/t/does-inlining-work-when-the-function-is-passed-as-an-argument/34470/2 "2020-02-11T15:20:46Z")

</div>

Yes, it can get inlined (but be aware of [Performance Tips · The Julia Language](https://docs.julialang.org/en/v1.5-dev/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing-1)).

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [February 11, 2020, 3:55pm UTC](https://discourse.julialang.org/t/does-inlining-work-when-the-function-is-passed-as-an-argument/34470/3 "2020-02-11T15:55:40Z")

</div>

As an aside, it’s a matter of convention to place function arguments first (even ahead of mutated arguments). This allows you to support [do](https://docs.julialang.org/en/v1/base/base/#do) syntax.
