Argument-type declarations normally have no impact on performance: regardless of what argument types (if any) are declared, Julia compiles a specialized version of the function for the actual argument types passed by the caller. For example, calling fib(1) will trigger the compilation of specialized version of fib optimized specifically for Int arguments, which is then re-used if fib(7) or fib(15) are called.
The provided example:
fib(n::Integer) = n ≤ 2 ? one(n) : fib(n-1) + fib(n-2)
but then in the Performance Tips:
# This will not specialize:
function f_type(t) # or t::Type
x = ones(t, 10)
return sum(map(sin, x))
end
From my understanding of the performance tips, with or without type annotations fib(b::Integer)
or fib(b)
shouldn't specialize specifically for Int
arguments.
It seems with or without the type annotation no specialization will happen, but why does the manual seem to indicate that it will specialize?