The mechanics of dispatch

I’d like to understand the mechanics of runtime dispatching with untyped or partially-typed arguments a bit better. I found some useful information here and here, with the money quotes being

It does a full method signature dispatch match at runtime if the types can’t be concretely inferred at compile time. - Jameson

If you do end up in a situation where type inference can’t figure out what method to call, dispatch can get kind of slow, but it’s still comparable to method calls in Python or Ruby. - Stefan

And the dev docs were informative.

What is the algorithm for dispatching? For that matter, which data structure is used for the method tables? Of course, the first call with a given type tuple is slow, but how are the subsequent calls done? Are they cached via a hash-table, or does Julia iteratively go through the method table at every call?

As far as I’m aware, the current approach was contributed in https://github.com/JuliaLang/julia/pull/17212.

3 Likes