Container type declaration when computing equivalence classes for performance vs genericity

It is advised in the performance section of the documentation that container type should not be AbstractType for better performance. I wonder what is the correct way to declare container partition, data in the following pseudocode and if these proper declaration will boost my performance. Note that I do know and control the output type of computeEquivalenceClass, computeAdditionalDatum.

baseSet = collect(1:10e10)
partition = [] # Array{Any}
data = [] # Array{Any}
while !isempty(baseSet)
    class = computeEquivalenceClass()
    datum = computeAdditionalDatum()
    push!(partition, class)
    push!(data, datum)
    filter!(k->!(k in class), baseSet)
end

Thank you.

If, for example, class is of type MyClass initialize partition with:

partition = MyClass[]

or, if you feel to be more explicit,

partition = Vector{MyClass}(undef,0)

But all this should be inside a function, otherwise partition will be type unstable anyway.

2 Likes