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

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:

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 @reexports?

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.

1 Like

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.

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:

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

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

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

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

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:

@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.

1 Like