RFR 8203279 : Faster calculation of power of two (original) (raw)

David Holmes david.holmes at oracle.com
Thu May 17 03:48:51 UTC 2018


On 17/05/2018 1:01 PM, Ivan Gerasimov wrote:

On 5/16/18 7:44 PM, David Holmes wrote: On 17/05/2018 12:30 PM, Ivan Gerasimov wrote: Hi David!

On 5/16/18 6:12 PM, David Holmes wrote: Hi Ivan, Surely you need to back this up with some performance numbers! And verify not assume that numberOfLeadingZeroes is intrinsified! Yes, good point. Please find the benchmark with the results here: http://cr.openjdk.java.net/~igerasim/8203279/00/MyBenchmark.java It shows that the new version of HashMap. tableSizeFor() was (approximately) two times faster. Impressive. :) Thanks :) Of course it's not performance critical code, but why not optimize it by a tiny bit if possible? Do you think it's good to go?

I think I'd rather defer to a more performance oriented reviewer - paging Claes! ;-)

David

With kind regards, Ivan

Thanks, David

With kind regards, Ivan

Cheers, David

On 17/05/2018 10:32 AM, Ivan Gerasimov wrote: Hello!

In a few places we have code that rounds an integer up to the nearest power of two. It is done with a series of RSHOTFs and ORs, but it can possibly be done faster with the use of Integer.numberOfLeadingZeros (assuming it is intrinsified). Would you please help review this trivial optimization: BUGURL: https://bugs.openjdk.java.net/browse/JDK-8203279 WEBREV: http://cr.openjdk.java.net/~igerasim/8203279/00/webrev/ For HashMap.tableSizeFor() I created a simple test with a loop from Integer.MINVALUE to Integer.MAXVALUE (including), to make sure the result is the same. For TimSort.ensureCapacity() I checked all positive values of minCapacity.



More information about the core-libs-dev mailing list