# Compilation performance. Branching

**URL:** https://discourse.julialang.org/t/compilation-performance-branching/17973
**Category:** Performance
**Created:** [November 25, 2018, 11:12am UTC](https://discourse.julialang.org/t/compilation-performance-branching/17973 "2018-11-25T11:12:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![xanfus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xanfus/32/5813_2.png) [@xanfus](https://discourse.julialang.org/u/xanfus)
#### Post date: [November 25, 2018, 11:12am UTC](https://discourse.julialang.org/t/compilation-performance-branching/17973/1 "2018-11-25T11:12:30Z")

</div>

My physical model consists of results requested, test subjects and variable set of phenomena acting upon the subjects. It’s convenient to keep all phenomena-related function calls conditioned by if-else statements within main program for test-driven development and retrospection, but compilation time grows as big as 22 minutes. When non-production branches are cut, i.e. control flow is solved, manually, compilation time is reduced to 2 minutes. This is how i see original problem:  
X=1:N. _AX_ is code.

1. Create file “dummy.jl”. Write:

```julia
function dummy(;kwarg1=false,...,kwargN=false)
  for j=1:T
    if kwarg1
      execute A1
    end
    if kwarg2
      execute A2
    end
    .
    .
    .
    if kwargN
      execute AN
    end
  end
  nothing
end

```

1. Execute:

```julia
include(_PathToDummysFolder_*"dummy.jl")
dummy(kwarg1=true)

```

Do we already know, how does compilation time depend on N?  
OR  
Say, if _kwarg1_ is true, is compilation time dominated by O(_A1_)? Is compilation time dominated by O(_dummy_)?

I wonder if i may make version control system to merge just enough code for a task, where whole argument array of length 200+, destined to dummy’s real-world prototype, will be supplied to shell script, calling for e.g. git.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [November 25, 2018, 12:18pm UTC](https://discourse.julialang.org/t/compilation-performance-branching/17973/2 "2018-11-25T12:18:20Z")

</div>

First, please [quote your code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530).

I your problem truly has this simple structure, then I would guess that compile time would be dominated by O(1) factors; since there is nothing to infer. Also, a global `A` may be the source of most of your performance problems at runtime.

But why aren’t you using something like

```julia
(kwarg1 || kwarg2 || ...) ? A : nothing

```

or even

```julia
dummy(; kwargs...) = any(values(kwargs)) ? A : nothing

```

---

<div class="post-metadata">

### Author: ![xanfus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xanfus/32/5813_2.png) [@xanfus](https://discourse.julialang.org/u/xanfus)
#### Post date: [November 25, 2018, 12:26pm UTC](https://discourse.julialang.org/t/compilation-performance-branching/17973/3 "2018-11-25T12:26:26Z")

</div>

Thank you. I did mean “A” is not global variable, but code. I rewrite the post.

---

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [November 25, 2018, 1:13pm UTC](https://discourse.julialang.org/t/compilation-performance-branching/17973/4 "2018-11-25T13:13:17Z")

</div>

Can you afford runtime branches? Then you could add `@noinline`.

I think your problem is that inlining / IPO / constant prop lead to many versions of your function getting compiled. Each version initially contains all the code, and dead code elimination is afaik a pretty late step (in other words: you pay for inference and optimization of dead code during compilation).

This might have significant runtime costs, though (benchmark!).
