If mutiple dispatch is done at compile time, wouldn't that make things faster?

I’m not an expert in any sense, but can we not get MOAR speed if we don’t have to check types at runtime?
So, if my code is statically styled, would that make it faster?

The multiple dispatch in Julia is done semantically at runtime, but an implementation is free to dispatch to a specific method at compile time if it can be proven that the result is indistinguishable from the runtime dispatch.

In fact, the compiler does such analysis and tries to eliminate runtime type checks. If it can do that without extra hints, the hints don’t make anything faster. The idea is to make the compiler infer and propagate types and remove runtime checks mostly by using generic functions such as float(x), promote(x, y, z...) etc. instead of explicit type declarations.

7 Likes

so, all we need to do, is write type-stable functions. There’s nothing else that we can help with as we write code.

It is better to avoid thinking about things you can do to help Julia do what Julia does, as Julia does that already. Paying attention to the performance tips should suffice for most purposes. With specific situtations, it is better to ask than to presume you should do something special. Usually the response will be either “you are fine with the approach taken” or “you may want to try using {some} package” or “try organizing it {this} way” and similar.

4 Likes