# Is it possible to precompile a function in Julia?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-precompile-a-function-in-julia/86578>\
**Category:** Performance\
**Tags:** precompilation, function\
**Created:** [August 31, 2022, 12:23am UTC](https://discourse.julialang.org/t/is-it-possible-to-precompile-a-function-in-julia/86578 "2022-08-31T00:23:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![valperez](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@valperez](https://discourse.julialang.org/u/valperez)\
**Post date:** [August 31, 2022, 12:23am UTC](https://discourse.julialang.org/t/is-it-possible-to-precompile-a-function-in-julia/86578/1 "2022-08-31T00:23:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 31, 2022, 3:28am UTC](https://discourse.julialang.org/t/is-it-possible-to-precompile-a-function-in-julia/86578/2 "2022-08-31T03:28:38Z")

</div>

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](https://discourse.julialang.org/t/best-practise-organising-code-in-julia/74362/2)

---

<div class="post-metadata">

**Author:** ![valperez](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@valperez](https://discourse.julialang.org/u/valperez)\
**Post date:** [August 31, 2022, 10:02pm UTC](https://discourse.julialang.org/t/is-it-possible-to-precompile-a-function-in-julia/86578/3 "2022-08-31T22:02:05Z")

</div>

Okey, thank you very much.
