RFR: 8151123 - Collectors.summingDouble/averagingDouble unnecessarily call mapper twice

Paul Sandoz paul.sandoz at oracle.com
Thu Mar 3 10:38:32 UTC 2016


> On 3 Mar 2016, at 10:26, Tagir F. Valeev <amaembo at gmail.com> wrote:
> 
> Hello!
> 
> Please review and sponsor this small change:
> 
> https://bugs.openjdk.java.net/browse/JDK-8151123
> http://cr.openjdk.java.net/~tvaleev/webrev/8151123/r1/
> 
> User-supplied mapper function is unnecessarily called twice on each
> accumulation event in summingDouble and averagingDouble. This function
> could be computationally intensive which may degrade the performance
> up to 2x. The patch addresses this issue.
> 

+1 An embarrassing oversight missed in review, well spotted. I can push for you.

—

I find it annoying we have to maintain the compensated and uncompensated sum for the edge case of the compensated sum being NaN and the simple sum being infinite. I measured this a while back i was surprised it did not appear to make much difference when loops are unrolled and vectored instructions are used, but i did perform an in-depth investigation.

https://bugs.openjdk.java.net/browse/JDK-8035561 <https://bugs.openjdk.java.net/browse/JDK-8035561>

Paul.


> Here's also simple JMH benchmark which illustrates the performance
> gain.
> http://cr.openjdk.java.net/~tvaleev/webrev/8151123/jmh/
> 
> Original:
> 
> Benchmark                         (n)  Mode  Cnt     Score    Error  Units
> AveragingTest.averageDistance      10  avgt   30     0,571 ±  0,049  us/op
> AveragingTest.averageDistance    1000  avgt   30    58,573 ±  1,194  us/op
> AveragingTest.averageDistance  100000  avgt   30  5854,428 ± 71,242  us/op
> 
> Patched:
> 
> Benchmark                         (n)  Mode  Cnt     Score    Error  Units
> AveragingTest.averageDistance      10  avgt   30     0,336 ±  0,002  us/op
> AveragingTest.averageDistance    1000  avgt   30    31,932 ±  0,367  us/op
> AveragingTest.averageDistance  100000  avgt   30  3794,541 ± 21,599  us/op
> 
> With best regards,
> Tagir Valeev.
> 




More information about the core-libs-dev mailing list