# How to cut down compile time when inference is not the problem?

**URL:** <https://discourse.julialang.org/t/how-to-cut-down-compile-time-when-inference-is-not-the-problem/59077>\
**Category:** Performance\
**Created:** [April 12, 2021, 8:18am UTC](https://discourse.julialang.org/t/how-to-cut-down-compile-time-when-inference-is-not-the-problem/59077 "2021-04-12T08:18:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fverdugo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fverdugo/32/9446_2.png) [@fverdugo](https://discourse.julialang.org/u/fverdugo)\
**Post date:** [April 12, 2021, 8:18am UTC](https://discourse.julialang.org/t/how-to-cut-down-compile-time-when-inference-is-not-the-problem/59077/1 "2021-04-12T08:18:11Z")

</div>

# Background

In [Gridap.jl](https://github.com/gridap/Gridap.jl), we have experienced a significant increase in compile times when moving from Julia 1.5 to Julia 1.6. To illustrate this, consider this example:

```julia-auto
using Gridap
function main()
  domain = (0,1,0,1,0,1); cells = (3,3,3); k = 2
  γ = 10; h = 1/3
  model = simplexify(CartesianDiscreteModel(domain,cells))
  reffe = ReferenceFE(lagrangian,Float64,k)
  V = TestFESpace(model,reffe,dirichlet_tags="boundary")
  U = TrialFESpace(V)
  Ω = Triangulation(model)
  Γ = BoundaryTriangulation(model)
  Λ = SkeletonTriangulation(model)
  dΩ = Measure(Ω,2*k)
  dΓ = Measure(Γ,2*k)
  dΛ = Measure(Λ,2*k)
  n_Γ = get_normal_vector(Γ)
  n_Λ = get_normal_vector(Λ)
  a(u,v) = ∫( ∇(v)⋅∇(u) )dΩ +
    ∫( (γ/h)*v*u - v*(n_Γ⋅∇(u)) - (n_Γ⋅∇(v))*u )dΓ +
    ∫( (γ/h)*jump(v*n_Λ)⋅jump(u*n_Λ) -
       jump(v*n_Λ)⋅mean(∇(u)) -
       mean(∇(v))⋅jump(u*n_Λ) )dΛ
  l(v) = ∫( v )dΩ
  op = AffineFEOperator(a,l,U,V)
  uh = solve(op)
end

```

Calling

```julia
@time main()

```

takes 92.353941 (Julia 1.5) vs 221.752225 (Julia 1.6) in a fresh session. So 2.4x increase. This is a major problem for us since 92 seconds was already a long compilation time.

I believe that Julia (i.e. inference time) is not to blame for the sudden increase. By running this in Julia 1.6:

```julia
julia> using SnoopCompile
julia> tinf = @snoopi_deep main()
InferenceTimingNode: 165.115502/226.610818 on InferenceFrameInfo for Core.Compiler.Timings.ROOT() with 1385 direct children

```

I get that 226.61081 is total compile time and 165.115502 is time in all phases except inference. Thus, inference time alone (61 seconds) does not explain the increase.

# Question

Which actions we need to take to cut down the compile time that does not come from inference?

[SnoopCompile](https://github.com/timholy/SnoopCompile.jl) Has a very nice tutorial on how to cut down inference times, but how to cut other phases?

We are looking forward for help since this is a major issue for us!

Thanks!

---

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [April 12, 2021, 8:22am UTC](https://discourse.julialang.org/t/how-to-cut-down-compile-time-when-inference-is-not-the-problem/59077/2 "2021-04-12T08:22:28Z")

</div>

Good question and I would also like to see any hints to improvements (although that’s probably a really hard problem). We experienced something similar in our hyperbolic PDE solver framework [Trixi.jl](https://github.com/trixi-framework/Trixi.jl), cf. [this Discourse thread](https://discourse.julialang.org/t/julia-v1-6-using-is-faster-but-first-call-is-slower/54838).

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 12, 2021, 1:28pm UTC](https://discourse.julialang.org/t/how-to-cut-down-compile-time-when-inference-is-not-the-problem/59077/3 "2021-04-12T13:28:51Z")

</div>

One major problem we found was tracked down to being about a map:

[https://github.com/SciML/SciMLBase.jl/pull/45](https://github.com/SciML/SciMLBase.jl/pull/45)

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [November 26, 2021, 7:59am UTC](https://discourse.julialang.org/t/how-to-cut-down-compile-time-when-inference-is-not-the-problem/59077/4 "2021-11-26T07:59:13Z")

</div>

Just testing my patched version of `Gridap.jl` from [here](https://discourse.julialang.org/t/extremely-high-first-call-latency-julia-1-6-versus-1-5-with-multiphysics-pde-solver/71692/22) yields

```julia
Julia Version 1.5.4
Commit 69fcb5745b (2021-03-11 19:13 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 6
 80.101978 seconds (159.74 M allocations: 7.881 GiB, 3.13% gc time)
SingleFieldFEFunction():
 num_cells: 162
 DomainStyle: ReferenceDomain()
 Triangulation: BodyFittedTriangulation()
 Triangulation id: 17548864358240605896

```

and

```julia
Julia Version 1.7.0-rc3
Commit 3348de4ea6 (2021-11-15 08:22 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 6
 81.666169 seconds (183.65 M allocations: 10.239 GiB, 3.45% gc time, 99.60% compilation time)
SingleFieldFEFunction():
 num_cells: 162
 DomainStyle: ReferenceDomain()
 Triangulation: BodyFittedTriangulation()
 Triangulation id: 4899376070316862521

```

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [November 26, 2021, 8:13am UTC](https://discourse.julialang.org/t/how-to-cut-down-compile-time-when-inference-is-not-the-problem/59077/5 "2021-11-26T08:13:33Z")

</div>

Checking performance with `@btime` yields

```julia
Julia Version 1.5.4
Commit 69fcb5745b (2021-03-11 19:13 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 6
  127.213 ms (1259619 allocations: 143.91 MiB)
SingleFieldFEFunction():
 num_cells: 162
 DomainStyle: ReferenceDomain()
 Triangulation: BodyFittedTriangulation()
 Triangulation id: 14490416472812666571

```

and

```julia
Julia Version 1.7.0-rc3
Commit 3348de4ea6 (2021-11-15 08:22 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 6
  123.524 ms (1275432 allocations: 131.42 MiB)
SingleFieldFEFunction():
 num_cells: 162
 DomainStyle: ReferenceDomain()
 Triangulation: BodyFittedTriangulation()
 Triangulation id: 5320699133180677141

```
