Hello, I have the following (simplified) code where I wonder why the second algorithm runs slower:

```
nn(x, bc) = x > 2 ? x : bc(x)
function algorithm_direct(Λ::AbstractArray{T, N}, bc::Function = x->x, bond_condition = (x, y) -> x == y) where {T, N}
for i ∈ Λ
bond_condition(i, nn(i, x->x))
end
end
function algorithm(Λ::AbstractArray{T, N}, bc::Function = x->x, bond_condition = (x, y) -> x == y) where {T, N}
for i ∈ Λ
bond_condition(i, nn(i, bc))
end
end
Λ = [1,2,3,4,5]
@btime algorithm_direct(Λ, x->x, (x, y) -> x == y )
@btime algorithm(Λ, x->x, (x, y) -> x == y )
```

This gives me:

```
401.069 ns (0 allocations: 0 bytes)
1.536 μs (0 allocations: 0 bytes)
```

So the question is, why the version with the function passed as parameter is slower than the version with fixed function in the call of `nn`

.

This is a running minimal example, the actual code is more difficult but the result is the same.

In the original case `@code_warntype`

tells me that `bc`

is **not** optimized out. I would like to have it behave in this way.

Thanks…