Note that you only pay the cost once per function call in your first case and not every time you access it inside the function. When x is inside the function it's type is known so everything there is fast. This is usually called a "function barrier" where you shield away your performance critical part from a type instability by putting it inside a function like this. Upon calling the function the type will be dynamically looked up but will then stay constant inside the function.
- [julia-users] Unexpected allocations in summing an arr... Darwin Darakananda
- [julia-users] Unexpected allocations in summing a... Kristoffer Carlsson
- [julia-users] Re: Unexpected allocations in s... Darwin Darakananda
- [julia-users] Re: Unexpected allocations ... Kristoffer Carlsson
- [julia-users] Re: Unexpected allocati... Kristoffer Carlsson
- [julia-users] Re: Unexpected all... Darwin Darakananda