Instead of dummy ifs, sort the message identifiers and emit a bisection for it. Even for 4 messages handled, this would result in a much less comparisons 2 (= log 4) vs 4 in a worst scenario. The branch prediction should be better as well, because the first bisection handles 50% of messages, where every dummy if depends on the message type.
If messages' identifiers are close enough, a switch jump table may be the way to go.
A mixed approach of two above? Ifs when gaps are big, switches where they're close?
Currently, the
MessageReader
uses ifs for dispatching the message by its type: https://github.com/Scooletz/RampUp/blob/master/src/RampUp/Actors/Impl/MessageReader.cs#L60 . There are two possible solutions to consider:switch
jump table may be the way to go.