# Understanding the performance issue in combine() \[DataFrames.jl\]

**URL:** <https://discourse.julialang.org/t/understanding-the-performance-issue-in-combine-dataframes-jl/59531>\
**Category:** Performance\
**Tags:** dataframes\
**Created:** [April 18, 2021, 12:02pm UTC](https://discourse.julialang.org/t/understanding-the-performance-issue-in-combine-dataframes-jl/59531 "2021-04-18T12:02:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DataFrames](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@DataFrames](https://discourse.julialang.org/u/DataFrames)\
**Post date:** [April 18, 2021, 12:02pm UTC](https://discourse.julialang.org/t/understanding-the-performance-issue-in-combine-dataframes-jl/59531/1 "2021-04-18T12:02:33Z")

</div>

I have the following performance issue with user defined function in combine(). Assume

```julia
df = DataFrame(g = rand(1:100,1000), x = rand(1000))

```

and

```julia
temp_fun(x) = sum(x)

```

the performance of combine() in the following two scenarios is very different, and I don’t understand how to overcome this

```julia
using BenchmarkTools
@btime combine(groupby(df, :g), :x=>sum);
29.429 μs (188 allocations: 41.00 KiB)
@btime combine(groupby(df, :g), :x=>temp_fun);
64.421 μs (1020 allocations: 78.31 KiB)

```

Any suggestion? thanks.

---

<div class="post-metadata">

**Author:** ![chris-b1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris-b1/32/14165_2.png) [@chris-b1](https://discourse.julialang.org/u/chris-b1)\
**Post date:** [April 18, 2021, 12:53pm UTC](https://discourse.julialang.org/t/understanding-the-performance-issue-in-combine-dataframes-jl/59531/2 "2021-04-18T12:53:00Z")

</div>

DataFrames has fast path implementations for groupby with certain functions like `sum` - you can see them in the code [here](https://github.com/JuliaData/DataFrames.jl/blob/a671a3b86537a253d461ff54b87ae2c26e4e8a04/src/groupeddataframe/fastaggregates.jl#L12)

Currently I don’t think there’s a public API way to opt-in for your own functions. If the op can be expressed as a reduction (e.g. `Base.add_sum` for `sum`), then you could replicate what DataFrames is doing, but that’s an internal API.
