# Performance of (a::AbstractType)(args...) function declarations

**URL:** <https://discourse.julialang.org/t/performance-of-a-abstracttype-args-function-declarations/29825>\
**Category:** Performance\
**Created:** [October 12, 2019, 5:36pm UTC](https://discourse.julialang.org/t/performance-of-a-abstracttype-args-function-declarations/29825 "2019-10-12T17:36:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![grahamas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grahamas/32/3401_2.png) [@grahamas](https://discourse.julialang.org/u/grahamas)\
**Post date:** [October 12, 2019, 5:36pm UTC](https://discourse.julialang.org/t/performance-of-a-abstracttype-args-function-declarations/29825/1 "2019-10-12T17:36:32Z")

</div>

I just finished refactoring my code to replace a lot of function calls of the form f(a::AbstractType, args…) with (a::AbstractType)(args…) since I can do that in 1.3, and it works out to slightly cleaner code. However, on testing I’m finding that the runtime has taken a massive hit, on the order of 1000x. Now, there were little things that I also fixed during this refactor, so the performance hit could be because of one of them, but before I go in and un-refactor and test all the various little things, I wanted to check if there’s any reason to expect that this primary, major change I made (defining calls on abstract types) would lead to a performance hit.

Preliminary profiling doesn’t show any glaring type instabilities.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [October 12, 2019, 5:54pm UTC](https://discourse.julialang.org/t/performance-of-a-abstracttype-args-function-declarations/29825/2 "2019-10-12T17:54:56Z")

</div>

Why don’t you try it on a minimal example? I don’t find any difference, so maybe your issue is unrelated to `(a::AbstractType)(args…) `.

```julia
julia> abstract type A end; struct B <: A end; b = B(); using BenchmarkTools; (::A)(x) = x * rand(); @btime b(2);
  22.957 ns (1 allocation: 16 bytes)

```

```julia
julia> abstract type A end; struct B <: A end; b = B(); using BenchmarkTools; (::B)(x) = x * rand(); @btime b(2);
  22.846 ns (1 allocation: 16 bytes)

```

Or perhaps I misunderstood what you meant?

---

<div class="post-metadata">

**Author:** ![grahamas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grahamas/32/3401_2.png) [@grahamas](https://discourse.julialang.org/u/grahamas)\
**Post date:** [October 12, 2019, 6:03pm UTC](https://discourse.julialang.org/t/performance-of-a-abstracttype-args-function-declarations/29825/3 "2019-10-12T18:03:08Z")

</div>

That’s a good point; I should have done that.

In any case that answers my question!

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 12, 2019, 6:45pm UTC](https://discourse.julialang.org/t/performance-of-a-abstracttype-args-function-declarations/29825/4 "2019-10-12T18:45:12Z")

</div>

Are you literally using splatting? I think that can be quite bad for performance.
