Is it possible to precompile a function in Julia?

Hi there,

I’m trying to make my Julia code as fast as possible and a friend of mine recommended using precompile. I have read about it but I’m not sure how to proceed, do I precompile the package I’m using o the function I’m creating? This is an example of my code:

`using GLM, Polynomials

function polynomial(k)

x_pol = Polynomials.fit(x, y, k)

return x_pol

end

precompile(polynomial, (Int64, ))`

I haven’t seen any changes in performance of the code when I add precompile(polynomial, (Int64, )) so I’m not sure how to proceed.

Thank you very much.

  1. Precompilation only speeds up code loading (i.e. startup time), not runtime performance. All Julia functions are compiled the first time you call them (with a particular set of argument types), and thereafter are fast.

  2. Precompilation is something that happens for code that you put into a package, which you should do for any longer-term development effort in Julia. See also Best practise: organising code in Julia - #2 by stevengj

3 Likes

Okey, thank you very much.