RFR: 8265029: Preserve SIZED characteristics on slice operations (skip, limit) [v2]

Tagir F.Valeev tvaleev at openjdk.java.net
Sun Apr 11 07:14:07 UTC 2021

On Sat, 10 Apr 2021 14:18:57 GMT, Vladimir Sitnikov <vsitnikov at openjdk.org> wrote:

>> Tagir F. Valeev has updated the pull request incrementally with one additional commit since the last revision:
>>   Fixes according to review:
>>   1. Comments in adjustSize
>>   2. repeating code extracted from testNoEvaluationForSizedStream
> test/micro/org/openjdk/bench/java/util/stream/ops/ref/SliceToList.java line 50:
>> 48:     @Benchmark
>> 49:     public List<String> seq_baseline() {
>> 50:         return IntStream.range(0, size)
> Typically you want to move all the constants to state fields to avoid constant folding by the compiler.
> The compiler might accidentally use the fact that range start is always 0 and produce a dedicated optimized code for it. 
> See https://shipilev.net/blog/2014/java-scala-divided-we-fail/

I know this article. Here, the upper bound is a state field, so the whole range cannot be optimized. And even if the compiler optimizes at the loop start, it's pretty common to have ranges starting with the constant 0 in the production, so I would not say that having 0 as an iteration starting point makes the benchmark more artificial. The same approach is used in neighbor benchmarks, and in fact, this is not the biggest problem with these benchmarks. Clean type profile makes them much more artificial than starting with zero. So I'd prefer keeping zero as is.


PR: https://git.openjdk.java.net/jdk/pull/3427

More information about the core-libs-dev mailing list