Where is the compiled code? Does julia compile the code on every run with `julia somescript.jl`

Hello,

I am actually developer and pick up interest in julia and using it to refresh my algorithm and math skills.

I am hard core vim user and I accustomed to write scripts, programs and compile them. I generally do not use REPL or fancy jupiter environments, other than to debug or learn things.

I know that julia uses jit compiler. I would like to understand that if I run an unmodified julia script with julia somescript.jl, does julia always compile again or is there a cache mechanism which uses artifacts of previous compilation. If so where are those binaries or artifacts?

I run scripts so many times and I feel as if julia always recompiles even though there is no change in the file or in the code. It is so annoying. Is there anything, I need to know or better approach?

As far as I know, scripts are always compiled again. There is some level of precompilation for modules, but binaries are not stored (yet). Of course, you can use package compiler to store compiled functions called in your module.

2 Likes

There is much active work on precompilation and static compilation, see e.g. GitHub - JuliaLang/PackageCompiler.jl: Compile your Julia Package and GitHub - tshort/StaticCompiler.jl: Compiles Julia code to a standalone library (experimental) The latter aims to allow static compilation to small binaries, but currently has limited language support, afaik.

Currently, by default, Julia code is recompiled each time when run outside a REPL, so REPL-based workflows are the most popular.

2 Likes

Using a REPL and putting all your code into functions is the usual way to go. If you edit a function and rerun the file in the REPL it will update all the function definitions.

If you are used to Vim, you might want to try VS code (with the Julia extension) as you can enable Vim bindings to edit your code like you are used to. You will also have a built in REPL so you can send code directly from your active file to the REPL with Ctrl+Enter.

You can use Julia with vim with a terminal or tmux window for the repl. Zepl.vim is pretty good. Or vim-slime.

But do learn to use the REPL. If you run scripts like that you will hate Julia, youre working against the design.

1 Like

Check out DaemonMode.jl. From the package’s README.md:

Inspired by the daemon-mode of Emacs, this package uses a server/client model. This allows julia to run scripts a lot faster, because the package is maintained in memory between the runs of (to run the same script several times).

1 Like

You could also experiment with some of the Julia startup options such as compile=min and/or --optimize=0 and see if this speeds up the total time required for your particular scripts. If your scripts mainly use calls to built-in functions that are already pre-compiled into the default startup image, this could result in a speedup for you.