# Strange way to recover performance with polymorphic types

**URL:** <https://discourse.julialang.org/t/strange-way-to-recover-performance-with-polymorphic-types/72250>\
**Category:** Performance\
**Tags:** question\
**Created:** [November 29, 2021, 5:23pm UTC](https://discourse.julialang.org/t/strange-way-to-recover-performance-with-polymorphic-types/72250 "2021-11-29T17:23:36Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![peremato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peremato/32/29128_2.png) [@peremato](https://discourse.julialang.org/u/peremato)\
**Post date:** [November 30, 2021, 8:41am UTC](https://discourse.julialang.org/t/strange-way-to-recover-performance-with-polymorphic-types/72250/5 "2021-11-30T08:41:56Z")

</div>

Thanks very much for your detailed reply and possible solutions. I am afraid that none is really fully satisfactory solution.

> [@lmiq](#):
>
> Annotate the output of extent:

This is really interesting and useful in other cases I have. I did attempt to annotate the actual definition of each `extent` function but it did not have any effect. In any case, there is still one allocation per call and is not the case when calling `extent_`.

> [@lmiq](#):
>
> Making `Figure` concrete:

I cannot do this since in the complete problem I do have a nested hierarchy of figures and I would require an heterogeneous vector of concrete figures. See the [initial thread](https://discourse.julialang.org/t/dramatic-performance-change-by-adding-additional-unused-method/71771).

> [@lmiq](#):
>
> Using the union types:

I will try this one providing that the limit is 16 or higher, although it suffers from the limitation that the module will no be extendable with additional figures provided by a client of the module.  
I wonder if `Union{Box, Circle, SBox, SCircle, Triangle,AbstrcatShape}` would allow me to add later additional shapes.

---

_[View the full topic](https://discourse.julialang.org/t/strange-way-to-recover-performance-with-polymorphic-types/72250)._
