Debugger hanging in `broadcast()` function call

When interactively stepping over some code I’ve written, using the VSCode debugging mode, the debugger does not step over the blockRF[...] = ... line (I have waiting several minutes). Setting a breakpoint at any point after this line results in the breakpoint never being reached.

for avgInd = 1:frameAverage
  interpIQ = resample(IQ[:,:,iqInd+avgInd-1], expData.intFac, dims=1)
  blockRF[:,:,avgInd] = real(broadcast(*, exp.(im*2pi*fs*times), interpIQ))
end

interpIQ is a three-dimensional array of ComplexF32 numbers. times is an Nx1 column vector of Float64 numbers, where N is the size of the first dimension of interpIQ. All other variables in that line are Float64 scalars (except for im, of course).

If I artificially remove the broadcast() call the debugger steps over the line with no problems.

FWIW, I am doing the debugging in VSCode.

I have tried to create a simplified test case. I think the following code illustrates the performance problem I am facing:

function test_debug(n,m)
    a = ones(n)
    b = Array{Float64}(undef, n, m)

    for i = 1:m
        b[:,i] = a .* a
    end

    return b
end

@time b = test_debug(3000,256)

I get the following output when I execute Julia: Run File in New Process:

> Executing task: /opt/homebrew/bin/julia --color=yes --project=/Volumes/GoogleDrive/My Drive/GitHub/offline-US-thermometry-Julia /Volumes/GoogleDrive/My Drive/GitHub/offline-US-thermometry-Julia/test_debug.jl <

  0.001663 seconds (516 allocations: 11.753 MiB)

When I execute Julia: Debug File in New Process I get:

> Executing task: /opt/homebrew/bin/julia --color=yes --startup-file=no --history-file=no --project=/Volumes/GoogleDrive/My Drive/GitHub/offline-US-thermometry-Julia /Users/ckumarad/.vscode/extensions/julialang.language-julia-1.6.17/scripts/debugger/run_debugger.jl /var/folders/v5/tr5ghhg10k194tq0r3bmsm640000gn/T/vsc-jl-dbg-e413caf6-41bc-4ab9-8701-1e885f3c709d /var/folders/v5/tr5ghhg10k194tq0r3bmsm640000gn/T/vsc-jl-cr-f8b551c2-3457-4864-a1b0-44a576b60a02 <

> Connecting to debugger... Done!

 22.084541 seconds (307.17 M allocations: 10.187 GiB, 2.21% gc time, 0.75% compilation time)

Why is running this in the debugger so much slower and why are there so many more allocations when running in the debugger?

I assume the slow-down is caused by the extra allocations. Is there a way around this?

Running it in the debugger means the code is interpreted instead of compiled, which means it runs a lot slower.

Thanks for the feedback. I am relatively new to Julia (coming from C and MATLAB).

Unfortunately, this makes debugging any code after that loop impractical since it may take days to get past that loop. Is there any workaround for this?

I can understand why interpreted code is much slower, but I do not understand why interpreted code would have more allocations.

You can use GitHub - JuliaDebug/Infiltrator.jl: No-overhead breakpoints in Julia to do breakpoint debugging, though you can’t step over etc. I imagine the allocations have to do with the interpreter itself and not your code.

1 Like