Does compilation time for methods depend on input?

Just a simple questions about compile times,

Say I have a function that takes an Integer argument and does some calculations depending on said integer.

Does the compilation time depend on how big the integer is? Say, for example:

function f(x::Integer)
    result = 0
    for i in 1:x

Will it take longer to compile




Compilation depends on input types but not values.

1 Like

I assume that you are talking about compiling f, not f(BigInt(2)). The former is a function, while the latter is a value.

The compiler doesn’t use the values of your inputs, only the types (except when it comes to constant propagation.) Otherwise, you would have to recompile the code each time you call it with a new value.

There is a slight ambiguity to your question, though. If you actually mean compile f(BigInt(2)), for example, if you have a larger code, and f(BigInt(2)) is on one of those lines, written out with a literal number 2; then, yes, the compiler might do the job of getting the value of f(BigInt(2)) or f(BigInt(2)^128), and in that case the difference might change compilation times.

But, most likely, you actually want to know about compiling f, not f(BigInt(2)).

1 Like

I guess this changed a bit with constant propagation, didn’t it? (Not that it would kick in for this example.)

1 Like

Well yes… but to a first approximation that’s just compiler nonsense :smile:


I know f(BigInt(2)) is a value, but when you type that into the REPL the function has to be compiled specifically for BigInt arguments. What I wanted to know is if having a bigger value for the argument causes the compilation time for f to be longer, but I see it is not the case.