# Peculiar Issue: The same function when defined in a package is 10x slower

**URL:** <https://discourse.julialang.org/t/peculiar-issue-the-same-function-when-defined-in-a-package-is-10x-slower/112110>\
**Category:** Performance\
**Created:** [March 25, 2024, 11:08pm UTC](https://discourse.julialang.org/t/peculiar-issue-the-same-function-when-defined-in-a-package-is-10x-slower/112110 "2024-03-25T23:08:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [March 25, 2024, 11:08pm UTC](https://discourse.julialang.org/t/peculiar-issue-the-same-function-when-defined-in-a-package-is-10x-slower/112110/1 "2024-03-25T23:08:28Z")

</div>

Hello!

I do not have a MWE since it is something I have spotted in developing a nested package. What I noticed is that if I have a function such as;

```julia
function SPHExample.ComputeInteractions!(Position, Kernel, KernelGradient, Density, Velocity, dρdtI, dvdtI, i, j, MotionLimiter, ρ₀, h, h⁻¹, m₀, αD, α, g, c₀, δᵩ, η², H², Cb⁻¹, ν₀, dx, SmagorinskyConstant, BlinConstant, ViscosityTreatment, BoolDDT, OutputKernelValues)
    xᵢⱼ² = evaluate(SqEuclidean(), Position[i], Position[j])
    if xᵢⱼ² <= H²
        xᵢⱼ = Position[i] - Position[j]
        
        dᵢⱼ = sqrt(xᵢⱼ²)
        q = clamp(dᵢⱼ * h⁻¹,0.0,2.0)
        invd²η² = inv(dᵢⱼ*dᵢⱼ+η²)
        ∇ᵢWᵢⱼ = @fastpow (αD*5*(q-2)^3*q / (8h*(q*h+η²)) ) * xᵢⱼ 
        ρᵢ = Density[i]
        ρⱼ = Density[j]
    
        vᵢ = Velocity[i]
        vⱼ = Velocity[j]
        vᵢⱼ = vᵢ - vⱼ
        density_symmetric_term = dot(-vᵢⱼ, ∇ᵢWᵢⱼ) # = dot(vᵢⱼ , -∇ᵢWᵢⱼ)
        dρdt⁺ = - ρᵢ * (m₀/ρⱼ) * density_symmetric_term
        dρdt⁻ = - ρⱼ * (m₀/ρᵢ) * density_symmetric_term
        # Do a lot more computations

```

If I define it inside my package then it runs 10x as slow as if I overload it and use it in a new script?

Has anyone experienced something similar and can give some tips?

Kind regards

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [March 26, 2024, 12:19am UTC](https://discourse.julialang.org/t/peculiar-issue-the-same-function-when-defined-in-a-package-is-10x-slower/112110/2 "2024-03-26T00:19:57Z")

</div>

Could you show us how you are timing it?
