I’m converting from Matlab (and some Python) to Julia. Honestly the time-to-first-plot issue of Julia really bothers me frequently. I almost never plot anything in Julia for that reason; instead, I save my (not so large) results to files, then load them up in Matlab or Python to plot. I am currently using a package for my computation needs, but that package also defines some convenient plotting functions based on Plots.jl, which I never use. Every time I need to load that package, it takes ages. When developing computation code and changing a function, sometimes I just want to quickly test if the code works correctly, but have to wait for it to be (re)compiled.
I’m aware of several ways to alleviate the issue (e.g., keep using one session, Revise.jl, Julia Interpreter,
PackageCompiler), but none is perfect. For example, with
--compile=min the packages are loaded more quickly, plotting may be faster, but my computation code will be much slower.
My main question: Is there any way (syntax) to specify whether a function should be compiled or not (i.e., executed by the interpreter instead)? This is more like a preference than a strict constraint. For instance, in the definition of function
myfun I can flag that it should be compiled or not (there will be a default, e.g., determined by
myfun is flagged as “compiled” it will always be compiled; if it is flagged as “not compiled” it will always be interpreted. That flag can be changed during run time, probably by a Julia base function. For example, if
myfun is originally “not compiled” but at some point I really need it to run fast, I can switch it to “compiled” then the next time it’s called, it will be compiled. After
myfun has been compiled, if I switch it back to “not compiled” the compiled version will still be used unless
myfun is changed. This flag can even be made a weight number, let’s say
0 means “never compiled”,
9 means “always compiled”, and
8 means the function will be compiled after being called frequently “enough” (how frequent is enough depends on the weight).
Usage: a developer can decide how a function should be compiled or interpreted. For example, most plotting and displaying functions can be “not compiled” for responsiveness, while computationally intensive functions are always compiled. When I am developing my computation code, I can start with “not compiled” so that I can quickly test it, but once it’s done, I can switch it to “compiled”.