Scooletz / RampUp

.NET library providing performant low-alloc algorithms and structures. Use to speed up your app.
Apache License 2.0
91 stars 10 forks source link

A possibly faster message reader #12

Open Scooletz opened 8 years ago

Scooletz commented 8 years ago

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:

  1. 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.
  2. If messages' identifiers are close enough, a switch jump table may be the way to go.
  3. A mixed approach of two above? Ifs when gaps are big, switches where they're close?