# Strange performance issue with using parsed commandline parameters in calculation

**URL:** <https://discourse.julialang.org/t/strange-performance-issue-with-using-parsed-commandline-parameters-in-calculation/135010>\
**Category:** General Usage\
**Tags:** potential-bug\
**Created:** [January 12, 2026, 9:34pm UTC](https://discourse.julialang.org/t/strange-performance-issue-with-using-parsed-commandline-parameters-in-calculation/135010 "2026-01-12T21:34:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_wang/32/8535_2.png) [@Michael\_Wang](https://discourse.julialang.org/u/Michael_Wang)\
**Post date:** [January 12, 2026, 9:34pm UTC](https://discourse.julialang.org/t/strange-performance-issue-with-using-parsed-commandline-parameters-in-calculation/135010/1 "2026-01-12T21:34:59Z")

</div>

Hi. I am running into a strange performance issue when using parameters obtained from ArgParse.jl (also noted this in [Performance issue when using parsed\_args in computation. · Issue #139 · carlobaldassi/ArgParse.jl · GitHub](https://github.com/carlobaldassi/ArgParse.jl/issues/139)). If I read in a value from commandline and use it for a calculation (at least for the calculations I tested), I get a huge performance hit. If instead I just hardcode/assign the values without parsing, there is no performance issue. This was tested on linux and windows with julia 1.10 and 1.12. Below is a simplified snippet of code to reproduce the issue:

```julia-auto
using ArgParse

function parse_cmd()
    s = ArgParseSettings()
    @add_arg_table s begin
        "--N"
            arg_type = Int64
            default = 2
        "--w"
            arg_type = Float64
            default = 0.1
    end
    return parse_args(s)
end

function run_parsed!()
    parsed_args = parse_cmd()

    N = parsed_args["N"]
    w = parsed_args["w"]
    println("parsed test")
    println("val $(N) and type $(typeof(N))")
    println("val $(w) and type $(typeof(w))")

    val = 0.0
    @time for step = 1 : 100000000
        val += sqrt(N * w * sin(N * w)^2)
    end
end
function run_hardcoded!()
    parsed_args = parse_cmd()

    N = 2
    w = 0.1
    println("hardcoded test")
    println("val $(N) and type $(typeof(N))")
    println("val $(w) and type $(typeof(w))")

    val = 0.0
    @time for step = 1 : 100000000
        val += sqrt(N * w * sin(N * w)^2)
    end
end
run_parsed!()
run_hardcoded!()

```

This is the output

 ![Screenshot 2026-01-12 221304](https://global.discourse-cdn.com/julialang/original/3X/d/3/d304a398353f5ecd4014abb70e9d2091fdaa2a4e.png)

Note: for some reason this issue doesn’t arise on a cluster running julia 1.10, just three different laptops.

---

<div class="post-metadata">

**Author:** ![JADekker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jadekker/32/210281_2.png) [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Post date:** [January 12, 2026, 9:38pm UTC](https://discourse.julialang.org/t/strange-performance-issue-with-using-parsed-commandline-parameters-in-calculation/135010/2 "2026-01-12T21:38:47Z")

</div>

I don’t think the types of NN and WW can be inferred. You can use a function barrier to solve the resulting performance issue (i.e. put the calculation in a function that has NN and WW as arguments). That should solve the problem.

---

<div class="post-metadata">

**Author:** ![JADekker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jadekker/32/210281_2.png) [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Post date:** [January 12, 2026, 9:39pm UTC](https://discourse.julialang.org/t/strange-performance-issue-with-using-parsed-commandline-parameters-in-calculation/135010/3 "2026-01-12T21:39:49Z")

</div>

I think you can detect this in cases like this e.g. using @code\_warntype or some similar trick. But I’m not near a pc and haven’t used these packages before, so I’m just going by Julia intuition here!

---

<div class="post-metadata">

**Author:** ![Michael\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_wang/32/8535_2.png) [@Michael\_Wang](https://discourse.julialang.org/u/Michael_Wang)\
**Post date:** [January 12, 2026, 9:48pm UTC](https://discourse.julialang.org/t/strange-performance-issue-with-using-parsed-commandline-parameters-in-calculation/135010/4 "2026-01-12T21:48:33Z")

</div>

Ah thanks, that appears to be the issue, as least part of it. I feel kind of dumb for not realizing that. If I do the following it works (actually I don’t need `dosomething()`).

```julia-auto
function run_parsed!()
    parsed_args = parse_cmd()

    N::Int64 = parsed_args["N"]
    w::Float64 = parsed_args["w"]
    dosomething(N, w)
end
function dosomething(N::Int64, w::Float64)
    println("parsed test")
    println("val $(N) and type $(typeof(N))")
    println("val $(w) and type $(typeof(w))")

    val = 0.0
    @time for step = 1 : 100000000
        val += sqrt(N * w * sin(N * w)^2)
    end
end

```

I get a very small but nonzero performance issue (related to the function call somehow).

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/2/827ae5879c1c3a6b92e552459d1e1d190dbbf5a9.png)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [January 12, 2026, 9:58pm UTC](https://discourse.julialang.org/t/strange-performance-issue-with-using-parsed-commandline-parameters-in-calculation/135010/5 "2026-01-12T21:58:14Z")

</div>

Not entirely the call. The compiler just eliminated the `val` calculation (0.000000 seconds) in the hardcoded method because it can be inferred to be dead code. Try returning `val` from all of these methods and observe the timings.

---

<div class="post-metadata">

**Author:** ![Michael\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_wang/32/8535_2.png) [@Michael\_Wang](https://discourse.julialang.org/u/Michael_Wang)\
**Post date:** [January 12, 2026, 10:02pm UTC](https://discourse.julialang.org/t/strange-performance-issue-with-using-parsed-commandline-parameters-in-calculation/135010/6 "2026-01-12T22:02:05Z")

</div>

This is what I have now. The parsed one still performs slightly worse (note I get the same slightly worse performance if I perform the calculation in a separate function then return twice).

```julia-auto
using ArgParse

function parse_cmd()
    s = ArgParseSettings()
    @add_arg_table s begin
        "--N"
            arg_type = Int64
            default = 2
        "--w"
            arg_type = Float64
            default = 0.1
    end
    return parse_args(s)
end

function run_parsed!()
    parsed_args = parse_cmd()

    N::Int64 = parsed_args["N"]
    w::Float64 = parsed_args["w"]
    println("parsed test")
    println("val $(N) and type $(typeof(N))")
    println("val $(w) and type $(typeof(w))")

    val = 0.0
    @time for step = 1 : 100000000
        val += sqrt(N * w * sin(N * w)^2)
    end

    return val
end

function run_hardcoded!()
    parsed_args = parse_cmd()

    N = 2
    w = 0.1
    println("hardcoded test")
    println("val $(N) and type $(typeof(N))")
    println("val $(w) and type $(typeof(w))")

    val = 0.0
    @time for step = 1 : 100000000
        val += sqrt(N * w * sin(N * w)^2)
    end

    return val
end
run_parsed!()
run_hardcoded!()

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/c/7cfc778c36d0ca231e953ba65cdeb3614521c56b.png)

Edit: If I perform the for loop in a separate function for both cases, then the performance is the same for both (~0.25s).

---

<div class="post-metadata">

**Author:** ![Michael\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_wang/32/8535_2.png) [@Michael\_Wang](https://discourse.julialang.org/u/Michael_Wang)\
**Post date:** [January 12, 2026, 10:29pm UTC](https://discourse.julialang.org/t/strange-performance-issue-with-using-parsed-commandline-parameters-in-calculation/135010/7 "2026-01-12T22:29:10Z")

</div>

Oh I see now with @code\_warntype. In the hardcoded case, N and w are stored as Const() while in the parsed case they aren’t. That is the difference between the two now. Thanks everyone!
