# What does \_\_precompile\_\_ do?

**URL:** <https://discourse.julialang.org/t/what-does---precompile---do/282>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 14, 2016, 10:11am UTC](https://discourse.julialang.org/t/what-does---precompile---do/282 "2016-11-14T10:11:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [November 14, 2016, 10:11am UTC](https://discourse.julialang.org/t/what-does---precompile---do/282/1 "2016-11-14T10:11:55Z")

</div>

I am curious to understand better how ` __precompile__ ()` works. For example if I have a module containing

```julia
f(x::Int) = ...
f(x::Number) = ...
f(x) = ...
g(x::Float32) = f(x)

```

Is it true that machine code for `f(::Int)` is cached? What about `f(::Float32)`? What is done with the other declarations? Lowering? Can I control for which signatures machine code is cached (e.g. please cache machine code for all signatures occurring while executing `runtests.jl`.)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 14, 2016, 10:14am UTC](https://discourse.julialang.org/t/what-does---precompile---do/282/2 "2016-11-14T10:14:29Z")

</div>

This is the wrong category for this.

> [@jw3126](#):
>
> Can I control for which signatures machine code is cached (e.g. please cache machine code for all signatures occurring while executing runtests.jl.)

You might be interested in SnoopCompile:

> **[GitHub - timholy/SnoopCompile.jl: Making packages work faster with more...](https://github.com/timholy/SnoopCompile.jl)**
>
> Making packages work faster with more extensive precompilation - GitHub - timholy/SnoopCompile.jl: Making packages work faster with more extensive precompilation

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [November 14, 2016, 10:52am UTC](https://discourse.julialang.org/t/what-does---precompile---do/282/3 "2016-11-14T10:52:13Z")

</div>

Check this:

> <https://stackoverflow.com/questions/40116045/why-is-julia-taking-a-long-time-on-the-first-call-into-my-module/40140349#40140349>

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [November 14, 2016, 3:01pm UTC](https://discourse.julialang.org/t/what-does---precompile---do/282/4 "2016-11-14T15:01:34Z")

</div>

> [@](#):
>
> Is it true that machine code for `f(::Int)` is cached?

No. Only the inference result is cached.

> [@](#):
>
> Can I control for which signatures machine code is cached (e.g. please cache machine code for all signatures occurring while executing runtests.jl.)

You can’t control what machine code is cached but you can use `precompile` to control what inference is cached.

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [November 21, 2016, 5:57pm UTC](https://discourse.julialang.org/t/what-does---precompile---do/282/5 "2016-11-21T17:57:02Z")

</div>

Thanks, this clarified things for me!
