# Requires.jl and precompilation

**URL:** https://discourse.julialang.org/t/requires-jl-and-precompilation/53155
**Category:** General Usage
**Tags:** question
**Created:** [January 11, 2021, 1:19pm UTC](https://discourse.julialang.org/t/requires-jl-and-precompilation/53155 "2021-01-11T13:19:10Z")
**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: [January 11, 2021, 1:19pm UTC](https://discourse.julialang.org/t/requires-jl-and-precompilation/53155/1 "2021-01-11T13:19:10Z")

</div>

I have a question, about Requires.jl and precompilation. Say I have the following package:

```julia
module AxisArrayConversion
...
__init__ () = @require AxisArrays=... include("axis_arrays.jl")
end

```

Then things defined in the “axis\_arrays.jl” file will not get precompiled. Correct so far or is it more complicated?

Now suppose I have in addition another package:

```julia
module OtherPackage
using AxisArrays
using AxisArrayConversion

function f(...)
    # use stuff defined in axis_arrays.jl file
end

```

Will `OtherPackage.f` get precompiled?

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [January 12, 2021, 11:39pm UTC](https://discourse.julialang.org/t/requires-jl-and-precompilation/53155/2 "2021-01-12T23:39:07Z")

</div>

The term `precompile` is a little confusing, because it means different things. The standard `Precompiling SomePkg...` message by default means its caching the method definitions etc in your package. _Optionally_ you can also save the type-inferred code, but that requires that you either (1) _use_ the methods while the package is being built, or (2) explicitly call `precompile` while the package is being built.

To answer your direct question: the `@require` example, your methods will not even be cached, let alone in type-inferred form. In the second case, the method definition for `f` will be automatically cached. To cache the type-inferred form you’ll have to emit `precompile` directives.

---

<div class="post-metadata">

### Author: ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)
#### Post date: [January 9, 2023, 4:08pm UTC](https://discourse.julialang.org/t/requires-jl-and-precompilation/53155/3 "2023-01-09T16:08:26Z")

</div>

In case a type definition (e.g. `struct Alpha end`) takes place in `axis_arrays.jl`, is there a way to access and use it in `OtherPackage` ?

---

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [January 9, 2023, 5:33pm UTC](https://discourse.julialang.org/t/requires-jl-and-precompilation/53155/4 "2023-01-09T17:33:06Z")

</div>

@tim.holy how does the weak dependency system fit into this? Does this lead to caching the method definitions, unlike `Requires`?

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [January 9, 2023, 6:25pm UTC](https://discourse.julialang.org/t/requires-jl-and-precompilation/53155/5 "2023-01-09T18:25:23Z")

</div>

That’s right. You can also optionally precompile type-inferred and native code.
