While Julia’s compile-time dispatch serves Julia users well, in some cases, runtime dispatch is needed. Runtime dispatch in Julia is not designed to be performant. This proposal attempts to add a limited dispatching (including multiple dispatches) capability to Julia. The proposal is as follows:
- Base dispatch on binary traits.
- There can be at most 64 traits.
- Store these traits as bits in a 64-bits integer.
- Whenever using, mask the relevant bits needed for dispatch, then do a perfect hash to get the value.
This was inspired by the magic bitboard
There can also be many tricks, for example, you could allocate the first 32 bits for the first object, and the last 32 bits for the second object, and then when they “collide”, you OR the bits together to get the full 64-bit set, then you do the dispatch.
Combined with the FunctionWrappers.jl, this could be used to create virtual functions with high flexibility.
- Bits manipulation is to be abstracted away from users, but how do I expose all the capabilities of the system to the user?
- How would you handle the edge cases? While 64 bits stored and 16 bits dispatch is enough for many applications, how would you make an error or fallback system in case it fails?
How would I abstract this into a package? I want to give Julia a runtime dispatch it deserves.
Thank you, for reading. This is probably going to be my first package.