# Multiple Methods

**URL:** <https://discourse.julialang.org/t/multiple-methods/119006>\
**Category:** Performance\
**Created:** [September 3, 2024, 7:34pm UTC](https://discourse.julialang.org/t/multiple-methods/119006 "2024-09-03T19:34:06Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [September 4, 2024, 12:27am UTC](https://discourse.julialang.org/t/multiple-methods/119006/9 "2024-09-04T00:27:28Z")

</div>

> [@Satvik](#):
>
> I’m guessing there’s some clever compiler optimization when there are 3 or fewer methods of a function, but I’d also be curious to know what it is & how it works.

That’s correct, see the links in [Avoiding Vectors of Abstract Types - #20 by tim.holy](https://discourse.julialang.org/t/avoiding-vectors-of-abstract-types/61883/20) or [Elimination of (unnecessary) runtime dispatch allocations - #2 by mbauman](https://discourse.julialang.org/t/elimination-of-unnecessary-runtime-dispatch-allocations/113475/2) for more on this.

Solution-wise, I’m going to assume there are a finite number of possible `TestN` types. In that case, using a [sum types package](https://discourse.julialang.org/t/ann-moshi-v0-3-the-next-gen-mlstyle-gadt-extensible-pattern-matching-and-more/117613) like SumTypes.jl, DynamicSumTypes.jl, Moshi.jl, etc. would remove allocations related to type instability.

---

_[View the full topic](https://discourse.julialang.org/t/multiple-methods/119006)._
