Extremely slow debugging in VS Code

I am new to Julia. I installed the application and the VS Code extension. When I run very simple scripts, e.g. just plotting a sin() function, stepping through the program via breakpoints is nearly impossible. Stepping from one line to the next takes up to 3 seconds per line. This is unusable. Also, just starting the debugging takes up to 10 seconds each time. I cant use Julia this way.

Why is this? Shouldn’t it run well out of the box without tinkering? This leaves a bad taste and I tend to just pick Python or Matlab for this task. Here is the code:

using Plots
#gr()  # Use the GR backend

x = 0:0.1:2π  # Initial x values
y = sin.(x)   # Initial y values

# Create the initial plot
p = plot(x, y, xlabel="x", ylabel="sin(x)", legend=false, title="Live Updating Plot")
display(p)

# Update the plot in a loop
for i in 1:100
 y = sin.(x .+ i * 0.1)  # Shift the sine wave
 plot!(p, x, y)          # Update the plot
 display(p)
 sleep(0.01)              # Pause to simulate real-time updates
end
1 Like

https://modernjuliaworkflows.org/writing/#infiltrator.jl

I think what @xgdgsc is trying to say is that Infiltrator.jl is a very nice, very fast debugger (though REPL-based). I myself also use it as my main debugger.

For usage, see the blog post above, the Infiltrator.jl docs and for example this discourse How to use Infiltrator? - General Usage - Julia Programming Language.

Adding the @infiltrate (or Main.@infiltrate) statement to your code, is kinda like adding a debug point in the VSCode editor.

1 Like

Thank you. But I guess I don’t want to use an unofficial workaround just to get Julia up to a usable state. Very disappointing. I remember using it a few years ago in the Atom editor it was quite fast. Well I guess I have to use python instead.

Did you check this section of the manual: Settings to speed up the debugger ?

2 Likes

I did try ALL_MODULES_EXCEPT_MAIN. I dont see any difference. But this shouldnt be required when starting with a new language. I dont want to jump through hoops just to start working.

A first impression is important for any new programming language, but I feel hardly pushed back by this. So I will not spend time fixing this, which is sad, because Julia seems promising. if it doesnt work out of the box for simple stuff, Julia has no chance getting more popular.

Well, debugging a compiled language will always be more complicated/ slower than debugging an interpreted language.

While some improvements of the Julia debugger are to be expected in the future, for now you must decide what you want:

  • a good IDE and a high quality, easy to use debugger
  • or a very composable, easy to read language which is super fast in executing complex self-written code

For a. choose Python, for b. choose Julia. I myself never use a debugger. For debugging I call functions from the REPL. But that is a matter of taste.

4 Likes

Thank you. But if I am honest, python as well as matlab, yet even compiled languages as both c++ and c# behave faster and are more responsive than Julia. The compile time for simple scripts on current machines is nearly instand, which is this still faster than the Julia experience. I don’t want to bash on Julia, but I am heavily disappointed, sadly. This is the first time in any language that I negatively notice lag and delay during stepping while debugging.

If you have a good REPL, what do you need a debugger for? I just don’t understand. The REPL of Julia is far superior compared to Python, and for languages like C++ there is none at all.

A different language might require a different approach to programming, and if you do not want to change your habits just stick to Python.

Please, not this again. I need a debugger, there’s no reason to argue against that. A REPL cannot help me understand what is going wrong, linestepping is required.

While I find the tone of the OP pretty annoying, I also find the vs code debugger exceptionally slow at the moment, and crashing a lot. Not sure if my laptop is also acting up.

6 Likes

Now I am surprised. You don’t use a debugger? I can’t live without a debugger. How do you check if your programming logic works as intended? Don’t you need to step through functions line by line to observe what they do? This is the most essential tool in any programming environment and language.

I don’t want to sound annoying, it’s just stating the obvious. I just didn’t understand why this is so slow on modern high performance machines.

Why not? Just declare the variables you are interested in as global, call the function you are trying to debug and look at the content of the variables of interest. If your functions are too large, then your programming style is problematic.

Because the debugger executes the Julia code in interpreter mode, and this interpreter is not much optimized because it is not used a lot. You can decide to compile the parts of the code that you are not debugging, like packages that you are using, and then you get a reasonable speed. But you must decide and configure which parts get compiled and which gets interpreted.

Yeah but then it should be at least as fast as MATLAB… In comparison MATLAB is instand.

You are comparing a very old, closed source language (Matlab) with a new, open source language. Lots of $$$ went into the development of the Matlab development environment and debugger, a lot less (perhaps 1%) into the development of the Julia tooling.

To claim some Julia tooling should do this or that without contributing time or money is not fair and pointless, actually, because it will not change anything.

Feel free to improve the performance of JuliaInterpreter.jl or pay someone who does that for you.

Fair point.

1 Like

Hi MathMan, when you added ALL_MODULES_EXCEPT_MAIN, did you click “Apply default compiled modules/functions”? Found in the “Run and debug” tab in vscode:

This made things much better for me

edit: video for example of it not taking too long after adding ALL_MODULES_EXCEPT_MAIN. Also note I’m using @enter to debug a function, so I’ve put your code into a function.

2 Likes

Because the code is far to complicated, involving lots of complicated objects interacting, involving lots of iteration and optimization with automatic differentiation. A static snapshot of variables tells me nothing, I need to follow the program flow and discover where the optimization starts failing.

Please believe when I say I have spent hundreds of hours trying to make everything as simple as possible. But it is really hard to even find valid solutions.

5 Likes

I feel like this topic deserves a long nuanced blog post about the benefits of debugging versus testing (REPL-based or with an extensive test suite). But alas I don’t have one ready.

Some personal points:

  • The VSCode Julia debugger is slow. Really slow. We should acknowledge that pain point. However the VSCode plugin maintainers just dont have the time to improve that. And no one is helping them yet.
  • Interpreter.jl is really nice and in no way “an unofficial workaround”.
  • MATLAB debugging is incredibly easy. Probably too easy, thus causing a form of debug-driven development, which breaks down for large collaborative software projects. (I admit I was a debug-driven programmer in the past.)
  • A debugger is just one tool in a programmers toolkit.
  • My main debugging usecase is to quickly find the exact data that goes into the problematic function. And then build a reproducible test out of that.
4 Likes