I am new to Julia and I am using vscode with the Julia extension to run code. Unfortunately, Julia responds incredibly slow. Outputs into the terminal take 7-8 seconds every time I run this simple script.
a = 2
b = 3
c = a + b
Why does it take so long and what can I do to solve this? If I use Julia directly in the terminal it responds very fast, but obviously, I need to run scripts.
This simple script definitely shouldn’t take long to run. In my case, if I execute your simple script line by line, the first line takes about 2 seconds to show up and get executed. All the following lines are executed “instantaneously”.
First time startup of the Julia REPL in VSCode takes some time because it first has to precompile some dependencies for VSCode itself and for Revise. Try to run the script twice in a row without closing the terminal in VSCode. Does the second run also take as long as the first run?
I run the code via the run “run file” button. I am not sure what happens in the background. So I dont know if the extension closes the terminal. The second start does not differ noticible from the first one.
Try executing the script line by line.
Ctrl + Enter will do that.
This is actually much faster. So how do I execute the whole script this way?
Ctrl + Enter will execute the current line or selection (i.e. “send line to REPL”).
Shift + Enter will execute a code block which you can create by adding
## where you want a block to end (i.e. “send code block to REPL”).
You can look these commands up if you open the keyboard shortcut reference (
Ctrl + K Ctrl + S) and search for Julia.
The “Run File” button currently starts a new Julia process each time it’s used. I’d recommend using the
Julia: Execute File command instead, which reuses the current Julia REPL.
Yes, this is what I use as well. I’ve setup a personal shortcut for it to
Shift + Alt + Enter, maybe you want to do something similar, @MathMan.
Will have a look, thanks.
I’ve wondered about this. Why doesn’t the “Run file” button do this. I was definitely surprised when I heard it started a new process.