# What goes in a MyModule.jl file? (particularly do you use PrecompileTools.jl neatly?)

**URL:** <https://discourse.julialang.org/t/what-goes-in-a-mymodule-jl-file-particularly-do-you-use-precompiletools-jl-neatly/98880>\
**Category:** General Usage\
**Tags:** package\
**Created:** [May 15, 2023, 1:30pm UTC](https://discourse.julialang.org/t/what-goes-in-a-mymodule-jl-file-particularly-do-you-use-precompiletools-jl-neatly/98880 "2023-05-15T13:30:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [May 15, 2023, 1:30pm UTC](https://discourse.julialang.org/t/what-goes-in-a-mymodule-jl-file-particularly-do-you-use-precompiletools-jl-neatly/98880/1 "2023-05-15T13:30:00Z")

</div>

Hi everyone,

I like it when my code looks neat, I also love how much faster `PrecompileTools` makes TTFX in my modules. What I’m not sure on, however, is where to put the `@compile_workload` part of the package.

What I like is that my `MyModule.jl` is as minimal as possible, almost as if it weren’t Turing complete in the first place. I’m talking:

```julia
module MyModule

export MyType funk unfunk

using Funkinator

include("MyType.jl") # MyType
include("funktionality.jl") # funk, unfunk
include("internal_funk.jl")

end

```

i.e. exports, imports, includes.

Where are you putting your workloads? Additionally, where are you putting your `@reexport`s?

---

<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:** [May 16, 2023, 12:37pm UTC](https://discourse.julialang.org/t/what-goes-in-a-mymodule-jl-file-particularly-do-you-use-precompiletools-jl-neatly/98880/2 "2023-05-16T12:37:33Z")

</div>

Any time you’re using all this code in your regular work and think to yourself, “gosh I wish I didn’t have to wait for `unfunk(funk(args...))` to compile on first usage, I sure wish the developers had thought to precompile that!”, you just put a toy version of that command inside `@compile_workload`.

---

<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:** [May 16, 2023, 12:39pm UTC](https://discourse.julialang.org/t/what-goes-in-a-mymodule-jl-file-particularly-do-you-use-precompiletools-jl-neatly/98880/3 "2023-05-16T12:39:11Z")

</div>

Oh, and you can use `@reexport using Funkinator` and whatever it exports will be exported by `MyModule`. In other worse, `using MyModule` becomes a synonym for `using Funkinator, ...` where `...` might be a bunch of other packages you use with it.

---

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [May 16, 2023, 1:09pm UTC](https://discourse.julialang.org/t/what-goes-in-a-mymodule-jl-file-particularly-do-you-use-precompiletools-jl-neatly/98880/4 "2023-05-16T13:09:08Z")

</div>

Thanks for the response (and for your work on `PrecompileTools`!), what I’m not too keen on, from an aesthetics point of view, is that the `PrecompileTools` workflow looks a little out of place in `MyModule.jl`, especially when you’re doing a _lot_ of precompilation.

Specifically, everything that comes before `PrecompileTools` could (in a Julia world where this were the norm) be written nicely as a `.toml` file

Therefore the following:

```julia
module MyModule

export MyType funk unfunk

using Funkinator

include("MyType.jl") # MyType
include("funktionality.jl") # funk, unfunk
include("internal_funk.jl")

using PrecompileTools

@compile_workload begin
    args = (1, "foo", :bar)
    unfunk(funk(args...)
end

end

```

could be

```toml
name = "MyModule"
export = ["MyType", "funk", "unfunk"]
dependencies = ["Funkinator"]
includes = ["MyType.jl", "funktionality.jl", "internal_funk.jl"]

```

with the `PrecompileTools` part could be written something like

```julia
workloads = ["unfunk_funk.jl", "apply_funk.jl"]

```

which makes me think it would be better to write the corresponding part of `MyModule` as

```julia
using PrecompileTools

include("workloads/unfunk_funk.jl")
include("workloads/apply_funk.jl")

```

with `workloads` being a folder inside `src`, and `workloads/unfunk_funk.jl` being:

```julia
@setup_workload begin
    a = 1, 2, 3
    b = 'a', 'b', 'c'
    # some additional nontrivial setup...
    @compile_workload begin
    unfunk(funk(a...))
    unfunk(funk(b...))
    # some additional workload...
    end
end

```

I know there’s nothing stopping me from doing this in my own projects already, but I would like to see others’ thoughts on doing this as there may be something I’m overlooking or a better way of doing this neatly.
