belaban/JGroups — pull request #98 by maniksurtani (2013-08-25 09:33:16+00:00)
Title: Replace mod operations with bitwise AND where possible

This pull request replaces modular operations (%) with bitwise AND operations where used in a hot code path or in a loop. Modulus invokes division in most CPUs, and this is often 1 to 2 orders of magnitude slower than a bitwise AND.

Reflected in several places:

http://dhruba.name/2011/07/12/performance-pattern-modulo-and-powers-of-two/
http://scicomp.stackexchange.com/questions/187/why-is-division-so-much-more-complex-than-other-arithmetic-operations
http://disruptor.googlecode.com/files/Disruptor-1.0.pdf (Page 5, last paragraph)

I have also identified other areas in JGroups where this will apply, however it would require enforcing that certain configuration parameters are powers of 2 (or are internally upgraded to the closest power of two). These include STABLE, HashedTimingWheel and RATE_LIMITER.