Reading this, it seems that you focus a lot on getting things perfect from the beginning and this leads you down hacky and messy roads. It is likely that a good chunk of your frustration is triggered by the feeling of not making progress towards your actual goal because you feel you have to wade through a lot of mud. But doesn’t need to be that way! Don’t let perfect be the enemy of good! Focus on getting to the goal in some way and then go back in later to improve. Possibly with the help of this forum/slack/whatever. This will be a much more satisfying experience for you, because you feel the progress. Also the messy stuff (if required…) will feels much better because you can actually make a benchmark and then see the numbers go down (also one should never ever try to guess what is slow because that fails almost every time - measurement is the first step to optimization!). The mantra I try to live is
- Make it work
- Make it right
- Make it fast
(I didn’t invent it)
A comment about the scenario you describe: instead of trying a lot of complicated compile programming with nasty hacks and stuff to find a perfect hash, I think you can likely just redo the computation at runtime every time. At this point you wouldn’t know what the complicated compile optimization even gain you because you can’t measure it because you have no working code, do you?
Alternatively I would suggest to try using a sum type from DynamicSumTypes.jl to pack you element combinations into a single type and then just do the computation and rely on the compiler. Should be plenty fast and much easier.