Dispatch time using `Val` is an order of magnitude slower than looking up with `Dict`

  1. You must not use Val this way in real code. And that’s exactly because

    I know that this is probably a flagrant abuse of Val

  2. Dispatch is fundamentally more complex than a dict look up because type matching is much more complex than hash lookup and direct value comparison. Dict lookup also doesn’t need to worry about multiple matches/specifity/ambiguity. It may be possible to make dispatch matches dict lookup performance but it’ll never be better and will in general be much worse.

4 Likes