Is splitting the Julia code into smaller scripts impacting performance?

Hei there julians! Let’s say I’m working on a Julia App and I organize my code in a MAIN.jl script and mayn other scripts, which I call from the MAIN.jl with include(). The structure can be nested, so the scripts included in MAIN.jl can include() other script files as well.

And now let’s assume two case scenarious:

  1. I’m running my App directly from Julia, without precompilation
  2. I’m compiling my code into an executable and then I’m running it

Would my many include() calls impact performance in the the two cases above? My guess would be that, if at all, it would impact the parsing and compilation steps.

looking forward to your oppinions

It should have a negligible impact (compared with simply pasting all of the code into a single file).

However, if you are writing re-usable code, I would strongly encourage you to think about putting the re-usable pieces into modules/packages, rather than thinking of it as “scripts”. (And write callable functions, not runnable scripts.) See also Best practise: organising code in Julia - #2 by stevengj

3 Likes

@stevengj Thanks for the fast answer! I’m happy to hear that include() impact on performance is neglijible.
And yes, you are absolutely rigth, the best code organization is into modules/packages. And I’m doing that also. However, within one module, I still feel the need to split the code into smaller units, so that I can navigate it easier. It is just a personal preference, but already 100 lines of code in one file becomes too much for me and I’m splitting it as soon as I find a logical way to group the code. I would be happy with one big file if I my IDE (VSCode) would have some type of toggle sections.

1 Like

No worries — splitting large modules into multiple files with
include is standard practice in Julia.

1 Like

1 Like

Are you referring to code folding?

VSCode lets you hide code by folding at lines in the code that are allowed to be folded.
Check out the command palette for further information.

This makes it much easier to navigate large sections of code in one big script.

1 Like