RFR: 8196106: Support nested infinite or recursive flat mapped streams [v8]

Viktor Klang vklang at openjdk.org
Sat Apr 13 14:27:12 UTC 2024


> This PR implements Gatherer-inspired encoding of `flatMap` that shows that it is both competitive performance-wise as well as improve correctness.
> 
> Below is the performance of `Stream::flatMap` (for reference types):
> 
> Before this PR (on my MacBook, aarch64):
> 
> Non-short-circuiting:
> 
> Benchmark                 (size)   Mode  Cnt        Score       Error  Units
> FlatMap.par_array             10  thrpt   12   257582,480 ? 31360,242  ops/s
> FlatMap.par_array            100  thrpt   12    55202,015 ? 14011,668  ops/s
> FlatMap.par_array           1000  thrpt   12     6546,252 ?  3675,764  ops/s
> FlatMap.par_doublestream      10  thrpt   12   267423,410 ? 37338,089  ops/s
> FlatMap.par_doublestream     100  thrpt   12    27140,703 ?  4979,878  ops/s
> FlatMap.par_doublestream    1000  thrpt   12     2978,178 ?  1890,250  ops/s
> FlatMap.par_intstream         10  thrpt   12   268194,530 ? 37295,092  ops/s
> FlatMap.par_intstream        100  thrpt   12    30897,034 ?  5388,245  ops/s
> FlatMap.par_intstream       1000  thrpt   12     3969,043 ?  2494,641  ops/s
> FlatMap.par_longstream        10  thrpt   12   279756,861 ? 19519,497  ops/s
> FlatMap.par_longstream       100  thrpt   12    45733,955 ? 18385,144  ops/s
> FlatMap.par_longstream      1000  thrpt   12     5115,615 ?  4147,237  ops/s
> FlatMap.seq_array             10  thrpt   12  2937192,934 ? 58605,583  ops/s
> FlatMap.seq_array            100  thrpt   12    41859,462 ?   139,021  ops/s
> FlatMap.seq_array           1000  thrpt   12      442,677 ?     1,041  ops/s
> FlatMap.seq_doublestream      10  thrpt   12  4972651,093 ? 35997,267  ops/s
> FlatMap.seq_doublestream     100  thrpt   12    99265,005 ?   193,497  ops/s
> FlatMap.seq_doublestream    1000  thrpt   12     1037,030 ?     3,254  ops/s
> FlatMap.seq_intstream         10  thrpt   12  5133751,888 ? 23516,294  ops/s
> FlatMap.seq_intstream        100  thrpt   12   145166,206 ?   399,263  ops/s
> FlatMap.seq_intstream       1000  thrpt   12     1565,004 ?     3,207  ops/s
> FlatMap.seq_longstream        10  thrpt   12  5047029,363 ? 24742,300  ops/s
> FlatMap.seq_longstream       100  thrpt   12   233225,307 ?  7162,604  ops/s
> FlatMap.seq_longstream      1000  thrpt   12     2999,926 ?     9,945  ops/s
> 
> // Short-circuiting:
> 
> Benchmark                   (size)   Mode  Cnt       Score       Error  Units
> FlatMap.par_iterate_double      10  thrpt   12   46336,834 ?  6803,751  ops/s
> FlatMap.par_iterate_double     100  thrpt   12   15365,884 ?  2750,656  ops/s
> FlatMap.par_iterate_double    1000 ...

Viktor Klang has updated the pull request incrementally with one additional commit since the last revision:

  Addressing review feedback

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/18625/files
  - new: https://git.openjdk.org/jdk/pull/18625/files/7683a0f3..07e2818b

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=18625&range=07
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=18625&range=06-07

  Stats: 32 lines in 5 files changed: 0 ins; 1 del; 31 mod
  Patch: https://git.openjdk.org/jdk/pull/18625.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18625/head:pull/18625

PR: https://git.openjdk.org/jdk/pull/18625


More information about the core-libs-dev mailing list