Skip to content

Performance

Manual dispatch (1.5)

It is beneficial to manually dispatch at runtime when a variable could potentially take on many types (as far as the compiler knows) but we know that only a few of those are possible. This is done automatically for small unions (known as union splitting). But for parametric types, the compiler has to look up methods in the method table at runtime because they could be extended.

The package ManualDispatch.jl has a @unionsplit macro for this purpose. But AFAIK one may just as well write out an explicit if else. This would look weird:

if x isa A
  foo(x);
elseif x isa B
  foo(x);
end

but it seems to work. See the discussion on discourse.