On 07/12/2014 08:12 PM, Peter Levart wrote:
If we're willing to pay the price of special-casing the non-power-of-2
MAX_CAPACITY = (1 << 29) + (1 << 28), which amounts to approx. 4% of
performance,
The cause of performance drop is of course the conditional in:
297 private static int hash(Object x, int length) {
298 int h = System.identityHashCode(x);
299 // multiply by -127
300 h -= h << 7;
301 if (length < MAXIMUM_CAPACITY * 2) { // length is 2^n
302 // left-shift to use least bit as part of hash
303 return (h << 1) & (length - 1);
304 }
305 // assert length == MAXIMUM_CAPACITY * 2
306 // clamp
307 h &= (MAXIMUM_CAPACITY / 3 * 4 - 1);
308 // Multiply by 3/2 and reset 0th bit
309 return (h + (h >> 1)) & ~1;
310 }
If I change it to:
297 private static int hash(Object x, int length) {
298 int h = System.identityHashCode(x);
299 // multiply by -127
300 h -= h << 7;
302 // left-shift to use least bit as part of hash
303 return (h << 1) & (length - 1);
310 }
...performance is restored, but then of course it only works until table
is resized to 2*MAX_CAPACITY. Does anybody have any idea how to make it
faster?
Regards, Peter