Hi, I’d like to understand more about this topic:
The dangers of abusing multiple dispatch
https://docs.julialang.org/en/v1.6-dev/manual/performance-tips/#The-dangers-of-abusing-multiple-dispatch-(aka,-more-on-types-with-values-as-parameters)-1
I don’t understand when we will get combinatorial explosion, quote
For example, you might imagine using it to store information, e.g.
struct Car{Make, Model}
year::Int
...more fields...
end
and then dispatch on objects like
Car{:Honda,:Accord}(year, args...)
.
This might be worthwhile when either of the following are true:
- You require CPU-intensive processing on each
Car
, and it becomes vastly more efficient if you know theMake
andModel
at compile time and the total number of differentMake
orModel
that will be used is not too large.- You have homogenous lists of the same type of
Car
to process, so that you can store them all in anArray{Car{:Honda,:Accord},N}
When these do not hold, then it’s likely that you’ll get no benefit; worse, the resulting “combinatorial explosion of types” will be counterproductive.
Given Car{Make, Model} I guess we have combinations like:
Car{:Honda, :Civic)
Car{:Honda, :Accord)
Car{:Toyota, :Prius)
Car{:Toyota, :Corolla)
The combination should be Make x Model, which is polynomial (n*m), not exponential (n^m)
I wonder if someone can give a more elaborated example of the combinatorial explosion mentioned in the linked article?
Thanks