Stream.findFirst for unordered source optimization

Tagir F. Valeev amaembo at gmail.com
Fri Jan 22 06:19:06 UTC 2016


Hello!

Seems that currently Stream.findFirst is not optimized for unordered
source. I think it should work as findAny in this case. Here's a small
patch which fixes this:

http://cr.openjdk.java.net/~tvaleev/patches/findFirst/find_patch.txt

Simple JMH test:
http://cr.openjdk.java.net/~tvaleev/patches/findFirst/FindTest.java

Original:
http://cr.openjdk.java.net/~tvaleev/patches/findFirst/jmh_out_orig.txt
# JMH 1.11.2 (released 85 days ago)
# VM version: JDK 9-ea, VM 9-ea+99-2015-12-23-183325.javare.4146.nc
Benchmark                    Mode  Cnt      Score      Error  Units
FindTest.findAny             avgt   30  12439,631 ± 1787,866  us/op
FindTest.findAnyUnordered    avgt   30  12923,080 ± 1072,537  us/op
FindTest.findFirst           avgt   30  48047,467 ± 2713,489  us/op
FindTest.findFirstUnordered  avgt   30  52648,893 ± 3934,682  us/op

Patched:
http://cr.openjdk.java.net/~tvaleev/patches/findFirst/jmh_out_patched.txt
Benchmark                    Mode  Cnt      Score      Error  Units
FindTest.findAny             avgt   30  11312,238 ±  386,627  us/op
FindTest.findAnyUnordered    avgt   30  12136,953 ± 1536,817  us/op
FindTest.findFirst           avgt   30  47517,776 ± 2844,607  us/op
FindTest.findFirstUnordered  avgt   30  13147,492 ± 1140,592  us/op

If you think it's a reasonable thing to patch, I can log an issue,
generate webrev and check whether jtreg tests pass.

With best regards,
Tagir Valeev.




More information about the core-libs-dev mailing list