# How to recompile specific methods

**URL:** https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340
**Category:** New to Julia
**Created:** [June 3, 2021, 3:16pm UTC](https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340 "2021-06-03T15:16:54Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)
#### Post date: [June 3, 2021, 3:16pm UTC](https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340/1 "2021-06-03T15:16:55Z")

</div>

I don’t know why, but sometimes the precompilation produces strange results. Typically, a recompilation due to invalidation will fix the problem (even if there is essentially no change in the code). The technique of deleting the “\*.ji” file will not change the result, as it will re-run the problematic precompilation.  
(see the [comment below](https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340/7) for an example)

So, is there a way to prompt for a recompilation of specific methods?

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [June 3, 2021, 7:11pm UTC](https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340/2 "2021-06-03T19:11:34Z")

</div>

Not sure if this answers your question, but if you are using `Revise.jl` you can ask it to check changes and recompile a whole Module. But you may as well be having some age-of-the-world problems.

---

<div class="post-metadata">

### Author: ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)
#### Post date: [June 3, 2021, 8:37pm UTC](https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340/3 "2021-06-03T20:37:31Z")

</div>

Yes, I’m using `Revise.jl` for development, and applying the mechanism that `Revise.jl` uses may help me achieve my goal. However, it would be going too far into Julia’s internals.

I would like to suggest a workaround to users of packages (e.g. `Colors.jl`, which has been having the precompilation problem for over a year).

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [June 3, 2021, 8:59pm UTC](https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340/4 "2021-06-03T20:59:31Z")

</div>

> [@kimikage](#):
>
> So, is there a way to prompt for a recompilation of specific methods?

If I understand correctly, you could always use `precompile` on your required method signatures

```julia
help?> precompile
search: precompile __precompile__

  precompile(f, args::Tuple{Vararg{Any}})

  Compile the given function f for the argument tuple (of types) args, but do not execute it.

```

---

<div class="post-metadata">

### Author: ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)
#### Post date: [June 3, 2021, 11:13pm UTC](https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340/5 "2021-06-03T23:13:30Z")

</div>

I think `precompile` is the right approach in general, but it should not be useful for methods that are already precompiled/compiled.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 3, 2021, 11:49pm UTC](https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340/6 "2021-06-03T23:49:31Z")

</div>

Can you describe in more detail which problem you encountered and how it can be reproduced?

---

<div class="post-metadata">

### Author: ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)
#### Post date: [June 4, 2021, 12:29am UTC](https://discourse.julialang.org/t/how-to-recompile-specific-methods/62340/7 "2021-06-04T00:29:10Z")

</div>

Here is an example.

```julia
julia> using Colors, BenchmarkTools

julia> rgb_f64 = rand(RGB{Float64}, 1000);

julia> @btime convert.(XYZ{Float64}, $rgb_f64);
  130.900 μs (5760 allocations: 113.48 KiB)

julia> precompile(Tuple{typeof(convert), Type{XYZ{Float64}}, RGB{Float64}}) # for example
true

julia> @btime convert.(XYZ{Float64}, $rgb_f64);
  130.900 μs (5760 allocations: 113.48 KiB)

julia> @noinline Colors.pow12_5(x::Float64) = x^2 * exp(0.4 * log(x)) # force invalidation (the body is not changed)

julia> @btime convert.(XYZ{Float64}, $rgb_f64);
  50.700 μs (2 allocations: 23.52 KiB)

julia> versioninfo()
Julia Version 1.7.0-DEV.1133
Commit db8d09609c (2021-05-21 13:48 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

```

For the root causes, the following would be appropriate places for discussion, not here.  
[https://github.com/JuliaLang/julia/issues/35972](https://github.com/JuliaLang/julia/issues/35972)  
[https://github.com/JuliaLang/julia/issues/34055](https://github.com/JuliaLang/julia/issues/34055)
