# Allocations when splatting Triangle points

**URL:** <https://discourse.julialang.org/t/allocations-when-splatting-triangle-points/59792>\
**Category:** Performance\
**Tags:** geometry, staticarrays\
**Created:** [April 22, 2021, 10:03am UTC](https://discourse.julialang.org/t/allocations-when-splatting-triangle-points/59792 "2021-04-22T10:03:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [April 22, 2021, 10:03am UTC](https://discourse.julialang.org/t/allocations-when-splatting-triangle-points/59792/1 "2021-04-22T10:03:13Z")

</div>

I’m (finally) adding some distance functions to GeometryBasics.jl and I’m having a problem avoiding allocations when splatting to get the points of a triangle

```julia
using GeometryBasics
using BenchmarkTools
vect_to_center(p,a,b,c) = p-(a+b+c)/3
> @btime vect_to_center(p,a,b,c) setup=(p = Point3f0(rand(3)); a = Point3f0(rand(3)); b = Point3f0(rand(3)); c= Point3f0(rand(3)));
  2.700 ns (0 allocations: 0 bytes)
> @btime vect_to_center(p,t...) setup=(p = Point3f0(rand(3)); t = Triangle(Point3f0(rand(3)),Point3f0(rand(3)),Point3f0(rand(3))));
  298.459 ns (13 allocations: 384 bytes)

```

But if I grab them “manually” it works

```julia
> @btime vect_to_center(p,t.points.data...) setup=(p = Point3f0(rand(3)); t = Triangle(Point3f0(rand(3)),Point3f0(rand(3)),Point3f0(rand(3))));
  2.499 ns (0 allocations: 0 bytes)

```

What is the splat doing in my first example that my manual version is avoiding? Is there a cleaner approach?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 22, 2021, 10:29am UTC](https://discourse.julialang.org/t/allocations-when-splatting-triangle-points/59792/2 "2021-04-22T10:29:35Z")

</div>

It would be helpful if you posted enough code so that the timings can be reproduced with a copy paste.

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [April 22, 2021, 2:24pm UTC](https://discourse.julialang.org/t/allocations-when-splatting-triangle-points/59792/3 "2021-04-22T14:24:30Z")

</div>

I’ve added the `GeometryBasics` dependency in the example.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 22, 2021, 2:32pm UTC](https://discourse.julialang.org/t/allocations-when-splatting-triangle-points/59792/4 "2021-04-22T14:32:06Z")

</div>

On Julia 1.6 I get the same timings.
