Compile efficiency and argument-type declearation

Suppose I have a function defined as

function f(x,y)
    return x + y 
end 

Here I have no argument-type declearation. Does this mean julia has to generate as many methods as possible for this function in compiling?

If so, does this mean argument-type declearation will reduce the number of possible methods and thus enhance compile efficiency?

Julia only compiles a method when it sees, for the first time, a call to function with a new concrete type signature. In your example, it would compile f(Int, Int) if you run f(1, 2) for the first time ever. It will not compile anything else, so there is no compile time efficiency to be gained from having type declarations in your code.

2 Likes