# Multiple dispatch with more than 4 methods blocks type inference

**URL:** https://discourse.julialang.org/t/multiple-dispatch-with-more-than-4-methods-blocks-type-inference/49066
**Category:** Performance
**Created:** [October 26, 2020, 7:37pm UTC](https://discourse.julialang.org/t/multiple-dispatch-with-more-than-4-methods-blocks-type-inference/49066 "2020-10-26T19:37:32Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [October 26, 2020, 7:42pm UTC](https://discourse.julialang.org/t/multiple-dispatch-with-more-than-4-methods-blocks-type-inference/49066/2 "2020-10-26T19:42:39Z")

</div>

I believe discussion in this post can answer you question:

> [@Unstable type with dispatch by Val{:X}() with 5 functions](https://discourse.julialang.org/t/unstable-type-with-dispatch-by-val-x-with-5-functions/48072):
>
> When i use following code i have no problems with types using LinearAlgebra, BlockDiagonals function f1(x::Vector{T}, ::Int, ::Val{:A}) where T Diagonal(x) end function f1(x::Vector{T}, i::Int, ::Val{:B}) where T Diagonal(x .\* i) end function f1(x::Vector{T}, ::Int, ::Val{:C}) where T Diagonal(x) end function f1(x::Vector{T}, ::Int, ::Val{:D}) where T Diagonal(x) end function f2(x1, x2, a, b) x = Vector{Matrix}(undef, 2) x[1] = f1(x1, 2, Val{a}()) x[2] = f1(x2, 3, Va…

the idea is that

> [@schaerfo](#):
>
> in performance-critical sections

won’t have 4+ methods to look up, or at least the trade-off is the same at that point.

---

_[View the full topic](https://discourse.julialang.org/t/multiple-dispatch-with-more-than-4-methods-blocks-type-inference/49066)._
