# Cell list algorithm is slower than double for loop

**URL:** <https://discourse.julialang.org/t/cell-list-algorithm-is-slower-than-double-for-loop/36621>\
**Category:** Performance\
**Created:** [March 28, 2020, 1:49am UTC](https://discourse.julialang.org/t/cell-list-algorithm-is-slower-than-double-for-loop/36621 "2020-03-28T01:49:45Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [March 31, 2020, 6:18pm UTC](https://discourse.julialang.org/t/cell-list-algorithm-is-slower-than-double-for-loop/36621/18 "2020-03-31T18:18:03Z")

</div>

> [@Maize](#):
>
> I don’t quite understand ‘a parameterized data type to not restrict filed types too much’.

That’s fine. The topic is a bit complicated, I needed some time to grasp the concept.

Parametric types define structures whose fields can have multiple types, but those types must be declared before use. `Vector{Int}` is an example, with the type parameter `Int`.  
The above struct may be written as

```julia
struct PointsCells{P,C,S}
    points::P
    cell::C
    pairs::S
end

```

That makes it easier to play with various representations. Say, the points may be in a vector of tuples instead of a matrix, `Pair`s instead of 2-tuples may be used for `pairs`, while the structure definition won’t need any change if it’s parametric. I now often find myself writing a parametric type even when I don’t plan using multiple data representations, only because the concrete type names are too long.

Omitting field types hits performance, as the types then become non-inferrable at compile time, so it’s generally not recommended. But then again, you may do it to play with different representations and put concrete types once you’ve made the decision which one best suits your needs.

The manual entry on parametric types: [Types · The Julia Language](https://docs.julialang.org/en/v1/manual/types/#Parametric-Composite-Types-1)  
I’d also recommend the book discussed in topic [New book: Hands-on Design Patterns and Best Practices with Julia](https://discourse.julialang.org/t/new-book-hands-on-design-patterns-and-best-practices-with-julia/33712)

---

_[View the full topic](https://discourse.julialang.org/t/cell-list-algorithm-is-slower-than-double-for-loop/36621)._
