# Slow down from parametric type

**URL:** <https://discourse.julialang.org/t/slow-down-from-parametric-type/3383>\
**Category:** General Usage\
**Tags:** performance, parametric-types\
**Created:** [April 26, 2017, 1:29pm UTC](https://discourse.julialang.org/t/slow-down-from-parametric-type/3383 "2017-04-26T13:29:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [April 26, 2017, 1:29pm UTC](https://discourse.julialang.org/t/slow-down-from-parametric-type/3383/1 "2017-04-26T13:29:24Z")

</div>

I have a `World`-like object, that is passed without modification to most of the functions in my codebase. It has four fields, which I’ll call `air`, `fire`, `water`, `earth`. Each of these is heavily parametric (`typeof(world.air)` takes a whole paragraph). If I define

```julia
struct World{A, F, W}
   air::A
   fire::F
   water::W
   earth
end

```

my benchmark suite (on the second run to take out the compilation time) takes 133 seconds. But if I make `World` parametric in `earth` (`World{A, F, W, E}`), it takes 250 seconds. Profiling this code effectively is a challenge (it’s more-or-less an interpreter for a DSL). What are the likely causes for such a slowdown? There’s only one `World` type, whether it’s parametric in `earth` or not, so there shouldn’t be more methods defined.

---

<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 26, 2017, 4:03pm UTC](https://discourse.julialang.org/t/slow-down-from-parametric-type/3383/2 "2017-04-26T16:03:21Z")

</div>

> [@cstjean](#):
>
> What are the likely causes for such a slowdown?

Recompiling too much?

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [April 26, 2017, 4:07pm UTC](https://discourse.julialang.org/t/slow-down-from-parametric-type/3383/3 "2017-04-26T16:07:04Z")

</div>

I’m running the same code twice for each version, and reporting a slowdown on the second run, so there shouldn’t be any compilation involed, right?

---

<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 26, 2017, 4:14pm UTC](https://discourse.julialang.org/t/slow-down-from-parametric-type/3383/4 "2017-04-26T16:14:23Z")

</div>

Yeah, unless there’s something dynamic going on.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 26, 2017, 5:16pm UTC](https://discourse.julialang.org/t/slow-down-from-parametric-type/3383/5 "2017-04-26T17:16:27Z")

</div>

If you can run the code, why can’t you profile it?

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [April 26, 2017, 5:36pm UTC](https://discourse.julialang.org/t/slow-down-from-parametric-type/3383/6 "2017-04-26T17:36:30Z")

</div>

I can, and do profile it, but it’s painful (because it’s essentially an interpreter), so I was hoping for a clue to guide my search.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 26, 2017, 6:42pm UTC](https://discourse.julialang.org/t/slow-down-from-parametric-type/3383/7 "2017-04-26T18:42:22Z")

</div>

Just a guess: it’s possible that after your change, your code is no longer correctly inferring the concrete type of some `World` instance. One way that could happen is if somewhere you’re storing a `Vector{World{A, F, W}}` not a `Vector{World{A, F, W, E}}`.

`@code_warntype` should show you if that’s the case in a given function.

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [April 29, 2017, 2:17pm UTC](https://discourse.julialang.org/t/slow-down-from-parametric-type/3383/8 "2017-04-29T14:17:05Z")

</div>

Narrowed it down. It’s probably a compiler heuristic working against my use case:

[https://github.com/JuliaLang/julia/issues/21634](https://github.com/JuliaLang/julia/issues/21634)
