# Best approach for runtime dispatching inside a hot loop (heterogeneous tree structure)

**URL:** https://discourse.julialang.org/t/best-approach-for-runtime-dispatching-inside-a-hot-loop-heterogeneous-tree-structure/9442
**Category:** Performance
**Created:** [March 2, 2018, 8:10am UTC](https://discourse.julialang.org/t/best-approach-for-runtime-dispatching-inside-a-hot-loop-heterogeneous-tree-structure/9442 "2018-03-02T08:10:46Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)
#### Post date: [March 2, 2018, 10:03pm UTC](https://discourse.julialang.org/t/best-approach-for-runtime-dispatching-inside-a-hot-loop-heterogeneous-tree-structure/9442/8 "2018-03-02T22:03:09Z")

</div>

Let me just mention the following: if you decide to use `if` statements, the compiler has an optimization to recognize the following pattern

```julia
   if key == 1 
     ...
   elseif key == 2
     ...
   elseif key == 3
     ...
   else
   ...
   end

```

and transforms it to a jump-table in the machine-language code so that the running time is independent of the number of cases. Unfortunately, this optimization is broken on some platforms in 0.6 (i.e., erroneous machine-code is emitted) because of an LLVM bug, but in an earlier discourse discussion Yichao Yu posted instructions how to patch your 0.6 for this particular bug.

---

_[View the full topic](https://discourse.julialang.org/t/best-approach-for-runtime-dispatching-inside-a-hot-loop-heterogeneous-tree-structure/9442)._
