Hello Julia Community ,
I’m developing my first Julia package at the moment. In the main module of this package, there are many functions that call functions from other modules. For example:
module main_module function foo(; kwargs) include("Module_One.jl") x = Module_One.Function_One(kwargs...) return x end function bar(; kwargs) include("Module_Two.jl") y = Module_Two.Function_Two(kwargs...) return y end function baz(; kwargs...) include("Module_Three.jl") z = Module_Three.Function_Three(kwargs...) return z end
Unless I’m mistaken , if I call one of these functions regularly, e.g. foo(), then each time it will look to include Module_One, which seems wasteful…
To be more efficient, would it be wise/foolish to do the following instead?
module main_module function foo(; kwargs) (@isdefined Module_One) ? nothing : include("Module_One.jl") x = Module_One.Function_One(kwargs...) return x end
The idea being to skip re-including “Module_One” each time the function is called again…
Or is Julia efficient enough already that doing this is unnecessary?
Having tried to run code this way already, I tend to get a world age error the first time (i.e. The applicable method may be too new: running in world age 12345 ) but it works ok after the first run…
Any advice will be greatly appreciated