# Debugger hanging in \`broadcast()\` function call

**URL:** <https://discourse.julialang.org/t/debugger-hanging-in-broadcast-function-call/80909>\
**Category:** General Usage\
**Tags:** debugging, vscode\
**Created:** [May 11, 2022, 7:42pm UTC](https://discourse.julialang.org/t/debugger-hanging-in-broadcast-function-call/80909 "2022-05-11T19:42:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ckumarad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ckumarad/32/36168_2.png) [@ckumarad](https://discourse.julialang.org/u/ckumarad)\
**Post date:** [May 11, 2022, 7:42pm UTC](https://discourse.julialang.org/t/debugger-hanging-in-broadcast-function-call/80909/1 "2022-05-11T19:42:12Z")

</div>

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.

```julia
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.

---

<div class="post-metadata">

**Author:** ![ckumarad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ckumarad/32/36168_2.png) [@ckumarad](https://discourse.julialang.org/u/ckumarad)\
**Post date:** [May 12, 2022, 8:07pm UTC](https://discourse.julialang.org/t/debugger-hanging-in-broadcast-function-call/80909/2 "2022-05-12T20:07:48Z")

</div>

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

```julia
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`:

```julia
> 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:

```julia
> 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?

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [May 12, 2022, 10:40pm UTC](https://discourse.julialang.org/t/debugger-hanging-in-broadcast-function-call/80909/3 "2022-05-12T22:40:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ckumarad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ckumarad/32/36168_2.png) [@ckumarad](https://discourse.julialang.org/u/ckumarad)\
**Post date:** [May 13, 2022, 12:20am UTC](https://discourse.julialang.org/t/debugger-hanging-in-broadcast-function-call/80909/4 "2022-05-13T00:20:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [May 13, 2022, 1:15am UTC](https://discourse.julialang.org/t/debugger-hanging-in-broadcast-function-call/80909/5 "2022-05-13T01:15:46Z")

</div>

You can use [GitHub - JuliaDebug/Infiltrator.jl: No-overhead breakpoints in Julia](https://github.com/JuliaDebug/Infiltrator.jl) 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.
