Re: RFR: 8274715: Implement forEach in Collections.CopiesList [v3]
On Tue, 5 Oct 2021 17:51:31 GMT, Сергей Цыпанов wrote: >> Originally was proposed by Zheka Kozlov here: >> http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-December/057192.html >> >> Just a tiny optimization: we can use for-i loop instead of >> `Iterable.forEach()` which is relying on iterator. >> >> Simple benchmark demonstrates slight improvement: >> >> @State(Scope.Thread) >> @BenchmarkMode(Mode.AverageTime) >> @OutputTimeUnit(TimeUnit.NANOSECONDS) >> public class NCopiesBenchmarks { >> @Param({"10", "50", "100"}) >> int size; >> >> private List list; >> >> @Setup >> public void prepare() { >> list = Collections.nCopies(size, new Object()); >> } >> >> @Benchmark >> public void forEach(Blackhole bh) { >> list.forEach(bh::consume); >> } >> } >> >> >> >> before >> >> Benchmark (size) Mode CntScore >> Error Units >> NCopiesBenchmarks.forEach 10 avgt 50 40.737 ± >> 1.854 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 50 avgt 50 213.324 ± >> 3.784 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻³ >> B/op >> NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 100 avgt 50 443.171 ± >> 17.919 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± >> 0.001B/op >> NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 >>counts >> >> after >> >> Benchmark (size) Mode CntScore >> Error Units >> NCopiesBenchmarks.forEach 10 avgt 50 36.838 ± >> 0.065 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 50 avgt 50 191.173 ± >> 0.570 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 100 avgt 50 376.675 ± >> 2.476 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± >> 0.001B/op >> NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 >>counts > > Сергей Цыпанов has updated the pull request incrementally with one additional > commit since the last revision: > > 8274715: Properly format NCopiesBenchmarks.java I've never sponsored a github change and https://openjdk.java.net/sponsor/ is unhelpfully stale. Oh wait ... I now see https://wiki.openjdk.java.net/display/SKARA/Pull+Request+Commands#PullRequestCommands-/sponsor - PR: https://git.openjdk.java.net/jdk/pull/2524
Re: RFR: 8274715: Implement forEach in Collections.CopiesList [v3]
On Tue, 5 Oct 2021 17:51:31 GMT, Сергей Цыпанов wrote: >> Originally was proposed by Zheka Kozlov here: >> http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-December/057192.html >> >> Just a tiny optimization: we can use for-i loop instead of >> `Iterable.forEach()` which is relying on iterator. >> >> Simple benchmark demonstrates slight improvement: >> >> @State(Scope.Thread) >> @BenchmarkMode(Mode.AverageTime) >> @OutputTimeUnit(TimeUnit.NANOSECONDS) >> public class NCopiesBenchmarks { >> @Param({"10", "50", "100"}) >> int size; >> >> private List list; >> >> @Setup >> public void prepare() { >> list = Collections.nCopies(size, new Object()); >> } >> >> @Benchmark >> public void forEach(Blackhole bh) { >> list.forEach(bh::consume); >> } >> } >> >> >> >> before >> >> Benchmark (size) Mode CntScore >> Error Units >> NCopiesBenchmarks.forEach 10 avgt 50 40.737 ± >> 1.854 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 50 avgt 50 213.324 ± >> 3.784 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻³ >> B/op >> NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 100 avgt 50 443.171 ± >> 17.919 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± >> 0.001B/op >> NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 >>counts >> >> after >> >> Benchmark (size) Mode CntScore >> Error Units >> NCopiesBenchmarks.forEach 10 avgt 50 36.838 ± >> 0.065 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 50 avgt 50 191.173 ± >> 0.570 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 100 avgt 50 376.675 ± >> 2.476 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± >> 0.001B/op >> NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 >>counts > > Сергей Цыпанов has updated the pull request incrementally with one additional > commit since the last revision: > > 8274715: Properly format NCopiesBenchmarks.java Looks good! - Marked as reviewed by martin (Reviewer). PR: https://git.openjdk.java.net/jdk/pull/2524
Re: RFR: 8274715: Implement forEach in Collections.CopiesList [v2]
On Tue, 5 Oct 2021 09:18:57 GMT, Сергей Цыпанов wrote: >> Originally was proposed by Zheka Kozlov here: >> http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-December/057192.html >> >> Just a tiny optimization: we can use for-i loop instead of >> `Iterable.forEach()` which is relying on iterator. >> >> Simple benchmark demonstrates slight improvement: >> >> @State(Scope.Thread) >> @BenchmarkMode(Mode.AverageTime) >> @OutputTimeUnit(TimeUnit.NANOSECONDS) >> public class NCopiesBenchmarks { >> @Param({"10", "50", "100"}) >> int size; >> >> private List list; >> >> @Setup >> public void prepare() { >> list = Collections.nCopies(size, new Object()); >> } >> >> @Benchmark >> public void forEach(Blackhole bh) { >> list.forEach(bh::consume); >> } >> } >> >> >> >> before >> >> Benchmark (size) Mode CntScore >> Error Units >> NCopiesBenchmarks.forEach 10 avgt 50 40.737 ± >> 1.854 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 50 avgt 50 213.324 ± >> 3.784 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻³ >> B/op >> NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 100 avgt 50 443.171 ± >> 17.919 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± >> 0.001B/op >> NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 >>counts >> >> after >> >> Benchmark (size) Mode CntScore >> Error Units >> NCopiesBenchmarks.forEach 10 avgt 50 36.838 ± >> 0.065 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 50 avgt 50 191.173 ± >> 0.570 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 100 avgt 50 376.675 ± >> 2.476 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± >> 0.001B/op >> NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 >>counts > > Сергей Цыпанов has updated the pull request with a new target base due to a > merge or a rebase. The incremental webrev excludes the unrelated changes > brought in by the merge/rebase. The pull request contains four additional > commits since the last revision: > > - Merge branch 'master' into ncopies > - 8274715: Add NCopiesBenchmarks.java > - 8274715: Revert some irrelevant changes > - 8274715: Implement forEach in Collections.CopiesList Done - PR: https://git.openjdk.java.net/jdk/pull/2524
Re: RFR: 8274715: Implement forEach in Collections.CopiesList [v3]
> Originally was proposed by Zheka Kozlov here: > http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-December/057192.html > > Just a tiny optimization: we can use for-i loop instead of > `Iterable.forEach()` which is relying on iterator. > > Simple benchmark demonstrates slight improvement: > > @State(Scope.Thread) > @BenchmarkMode(Mode.AverageTime) > @OutputTimeUnit(TimeUnit.NANOSECONDS) > public class NCopiesBenchmarks { > @Param({"10", "50", "100"}) > int size; > > private List list; > > @Setup > public void prepare() { > list = Collections.nCopies(size, new Object()); > } > > @Benchmark > public void forEach(Blackhole bh) { > list.forEach(bh::consume); > } > } > > > > before > > Benchmark (size) Mode CntScore > Error Units > NCopiesBenchmarks.forEach 10 avgt 50 40.737 ± > 1.854 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 50 avgt 50 213.324 ± > 3.784 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻³ > B/op > NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 100 avgt 50 443.171 ± > 17.919 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± > 0.001B/op > NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 > counts > > after > > Benchmark (size) Mode CntScore > Error Units > NCopiesBenchmarks.forEach 10 avgt 50 36.838 ± > 0.065 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 50 avgt 50 191.173 ± > 0.570 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 100 avgt 50 376.675 ± > 2.476 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± > 0.001B/op > NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 > counts Сергей Цыпанов has updated the pull request incrementally with one additional commit since the last revision: 8274715: Properly format NCopiesBenchmarks.java - Changes: - all: https://git.openjdk.java.net/jdk/pull/2524/files - new: https://git.openjdk.java.net/jdk/pull/2524/files/18f5d589..7655be8f Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk=2524=02 - incr: https://webrevs.openjdk.java.net/?repo=jdk=2524=01-02 Stats: 13 lines in 1 file changed: 1 ins; 0 del; 12 mod Patch: https://git.openjdk.java.net/jdk/pull/2524.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/2524/head:pull/2524 PR: https://git.openjdk.java.net/jdk/pull/2524
Re: RFR: 8274715: Implement forEach in Collections.CopiesList [v2]
On Tue, 5 Oct 2021 09:18:57 GMT, Сергей Цыпанов wrote: >> Originally was proposed by Zheka Kozlov here: >> http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-December/057192.html >> >> Just a tiny optimization: we can use for-i loop instead of >> `Iterable.forEach()` which is relying on iterator. >> >> Simple benchmark demonstrates slight improvement: >> >> @State(Scope.Thread) >> @BenchmarkMode(Mode.AverageTime) >> @OutputTimeUnit(TimeUnit.NANOSECONDS) >> public class NCopiesBenchmarks { >> @Param({"10", "50", "100"}) >> int size; >> >> private List list; >> >> @Setup >> public void prepare() { >> list = Collections.nCopies(size, new Object()); >> } >> >> @Benchmark >> public void forEach(Blackhole bh) { >> list.forEach(bh::consume); >> } >> } >> >> >> >> before >> >> Benchmark (size) Mode CntScore >> Error Units >> NCopiesBenchmarks.forEach 10 avgt 50 40.737 ± >> 1.854 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 50 avgt 50 213.324 ± >> 3.784 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻³ >> B/op >> NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 100 avgt 50 443.171 ± >> 17.919 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± >> 0.001B/op >> NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 >>counts >> >> after >> >> Benchmark (size) Mode CntScore >> Error Units >> NCopiesBenchmarks.forEach 10 avgt 50 36.838 ± >> 0.065 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 50 avgt 50 191.173 ± >> 0.570 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻⁴ >> B/op >> NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 >>counts >> NCopiesBenchmarks.forEach 100 avgt 50 376.675 ± >> 2.476 ns/op >> NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± >> 0.001 MB/sec >> NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± >> 0.001B/op >> NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 >>counts > > Сергей Цыпанов has updated the pull request with a new target base due to a > merge or a rebase. The pull request now contains four commits: > > - Merge branch 'master' into ncopies > - 8274715: Add NCopiesBenchmarks.java > - 8274715: Revert some irrelevant changes > - 8274715: Implement forEach in Collections.CopiesList Thanks - TIL about Blackhole::consume . All Java source files should end with exactly one newline. Configure your editor to make it so. - Changes requested by martin (Reviewer). PR: https://git.openjdk.java.net/jdk/pull/2524
Re: RFR: 8274715: Implement forEach in Collections.CopiesList [v2]
On Mon, 4 Oct 2021 16:51:27 GMT, Martin Buchholz wrote: >> Сергей Цыпанов has updated the pull request with a new target base due to a >> merge or a rebase. The incremental webrev excludes the unrelated changes >> brought in by the merge/rebase. The pull request contains four additional >> commits since the last revision: >> >> - Merge branch 'master' into ncopies >> - 8274715: Add NCopiesBenchmarks.java >> - 8274715: Revert some irrelevant changes >> - 8274715: Implement forEach in Collections.CopiesList > > Core collection classes should have optimized versions of forEach, so this is > a good change in principle. Although CopiesList.forEach is unlikely to be > performance critical. > > I implemented many similar optimizations for core collection classes in past > years. > Many of them are benchmarked in > test/jdk/java/util/Collection/IteratorMicroBenchmark.java > That was written pre-JMH. > I see a JMH benchmark was written, but it is not part of the commit. > > There are a number of unrelated changes in this commit that look like they > were suggested by a lint-like tool. Such changes are good, but they belong > in a separate cleanup commit applied across large portions of the jdk sources. > > I would not use "var" here - more readable with concrete types. > > Similarly, I prefer not using diamond for > return new Enumeration() { @Martin-Buchholz thanks for review! I've reverted irrelevant changes and added the benchmark. - PR: https://git.openjdk.java.net/jdk/pull/2524
Re: RFR: 8274715: Implement forEach in Collections.CopiesList [v2]
> Originally was proposed by Zheka Kozlov here: > http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-December/057192.html > > Just a tiny optimization: we can use for-i loop instead of > `Iterable.forEach()` which is relying on iterator. > > Simple benchmark demonstrates slight improvement: > > @State(Scope.Thread) > @BenchmarkMode(Mode.AverageTime) > @OutputTimeUnit(TimeUnit.NANOSECONDS) > public class NCopiesBenchmarks { > @Param({"10", "50", "100"}) > int size; > > private List list; > > @Setup > public void prepare() { > list = Collections.nCopies(size, new Object()); > } > > @Benchmark > public void forEach(Blackhole bh) { > list.forEach(bh::consume); > } > } > > > > before > > Benchmark (size) Mode CntScore > Error Units > NCopiesBenchmarks.forEach 10 avgt 50 40.737 ± > 1.854 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 50 avgt 50 213.324 ± > 3.784 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻³ > B/op > NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 100 avgt 50 443.171 ± > 17.919 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± > 0.001B/op > NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 > counts > > after > > Benchmark (size) Mode CntScore > Error Units > NCopiesBenchmarks.forEach 10 avgt 50 36.838 ± > 0.065 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 50 avgt 50 191.173 ± > 0.570 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 100 avgt 50 376.675 ± > 2.476 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± > 0.001B/op > NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 > counts Сергей Цыпанов has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision: - Merge branch 'master' into ncopies - 8274715: Add NCopiesBenchmarks.java - 8274715: Revert some irrelevant changes - 8274715: Implement forEach in Collections.CopiesList - Changes: - all: https://git.openjdk.java.net/jdk/pull/2524/files - new: https://git.openjdk.java.net/jdk/pull/2524/files/2303aa72..18f5d589 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk=2524=01 - incr: https://webrevs.openjdk.java.net/?repo=jdk=2524=00-01 Stats: 1563723 lines in 16632 files changed: 815442 ins; 677273 del; 71008 mod Patch: https://git.openjdk.java.net/jdk/pull/2524.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/2524/head:pull/2524 PR: https://git.openjdk.java.net/jdk/pull/2524
Re: RFR: 8274715: Implement forEach in Collections.CopiesList
On Thu, 11 Feb 2021 13:28:49 GMT, Сергей Цыпанов wrote: > Originally was proposed by Zheka Kozlov here: > http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-December/057192.html > > Just a tiny optimization: we can use for-i loop instead of > `Iterable.forEach()` which is relying on iterator. > > Simple benchmark demonstrates slight improvement: > > @State(Scope.Thread) > @BenchmarkMode(Mode.AverageTime) > @OutputTimeUnit(TimeUnit.NANOSECONDS) > public class NCopiesBenchmarks { > @Param({"10", "50", "100"}) > int size; > > private List list; > > @Setup > public void prepare() { > list = Collections.nCopies(size, new Object()); > } > > @Benchmark > public void forEach(Blackhole bh) { > list.forEach(bh::consume); > } > } > > > > before > > Benchmark (size) Mode CntScore > Error Units > NCopiesBenchmarks.forEach 10 avgt 50 40.737 ± > 1.854 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 50 avgt 50 213.324 ± > 3.784 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻³ > B/op > NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 100 avgt 50 443.171 ± > 17.919 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± > 0.001B/op > NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 > counts > > after > > Benchmark (size) Mode CntScore > Error Units > NCopiesBenchmarks.forEach 10 avgt 50 36.838 ± > 0.065 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 50 avgt 50 191.173 ± > 0.570 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 100 avgt 50 376.675 ± > 2.476 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± > 0.001B/op > NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 > counts Core collection classes should have optimized versions of forEach, so this is a good change in principle. Although CopiesList.forEach is unlikely to be performance critical. I implemented many similar optimizations for core collection classes in past years. Many of them are benchmarked in test/jdk/java/util/Collection/IteratorMicroBenchmark.java That was written pre-JMH. I see a JMH benchmark was written, but it is not part of the commit. There are a number of unrelated changes in this commit that look like they were suggested by a lint-like tool. Such changes are good, but they belong in a separate cleanup commit applied across large portions of the jdk sources. I would not use "var" here - more readable with concrete types. Similarly, I prefer not using diamond for return new Enumeration() { - Changes requested by martin (Reviewer). PR: https://git.openjdk.java.net/jdk/pull/2524
Re: RFR: 8274715: Implement forEach in Collections.CopiesList
On Thu, 11 Feb 2021 13:28:49 GMT, Сергей Цыпанов wrote: > Originally was proposed by Zheka Kozlov here: > http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-December/057192.html > > Just a tiny optimization: we can use for-i loop instead of > `Iterable.forEach()` which is relying on iterator. > > Simple benchmark demonstrates slight improvement: > > @State(Scope.Thread) > @BenchmarkMode(Mode.AverageTime) > @OutputTimeUnit(TimeUnit.NANOSECONDS) > public class NCopiesBenchmarks { > @Param({"10", "50", "100"}) > int size; > > private List list; > > @Setup > public void prepare() { > list = Collections.nCopies(size, new Object()); > } > > @Benchmark > public void forEach(Blackhole bh) { > list.forEach(bh::consume); > } > } > > > > before > > Benchmark (size) Mode CntScore > Error Units > NCopiesBenchmarks.forEach 10 avgt 50 40.737 ± > 1.854 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 50 avgt 50 213.324 ± > 3.784 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻³ > B/op > NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 100 avgt 50 443.171 ± > 17.919 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± > 0.001B/op > NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 > counts > > after > > Benchmark (size) Mode CntScore > Error Units > NCopiesBenchmarks.forEach 10 avgt 50 36.838 ± > 0.065 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 50 avgt 50 191.173 ± > 0.570 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻⁴ > B/op > NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 > counts > NCopiesBenchmarks.forEach 100 avgt 50 376.675 ± > 2.476 ns/op > NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± > 0.001 MB/sec > NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± > 0.001B/op > NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 > counts Marked as reviewed by li...@github.com (no known OpenJDK username). - PR: https://git.openjdk.java.net/jdk/pull/2524
RFR: 8274715: Implement forEach in Collections.CopiesList
Originally was proposed by Zheka Kozlov here: http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-December/057192.html Just a tiny optimization: we can use for-i loop instead of `Iterable.forEach()` which is relying on iterator. Simple benchmark demonstrates slight improvement: @State(Scope.Thread) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public class NCopiesBenchmarks { @Param({"10", "50", "100"}) int size; private List list; @Setup public void prepare() { list = Collections.nCopies(size, new Object()); } @Benchmark public void forEach(Blackhole bh) { list.forEach(bh::consume); } } before Benchmark (size) Mode CntScore Error Units NCopiesBenchmarks.forEach 10 avgt 50 40.737 ± 1.854 ns/op NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± 0.001 MB/sec NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ B/op NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 counts NCopiesBenchmarks.forEach 50 avgt 50 213.324 ± 3.784 ns/op NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± 0.001 MB/sec NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻³ B/op NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 counts NCopiesBenchmarks.forEach 100 avgt 50 443.171 ± 17.919 ns/op NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± 0.001 MB/sec NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± 0.001B/op NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 counts after Benchmark (size) Mode CntScore Error Units NCopiesBenchmarks.forEach 10 avgt 50 36.838 ± 0.065 ns/op NCopiesBenchmarks.forEach:·gc.alloc.rate 10 avgt 500.001 ± 0.001 MB/sec NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 10 avgt 50 ≈ 10⁻⁴ B/op NCopiesBenchmarks.forEach:·gc.count10 avgt 50 ≈ 0 counts NCopiesBenchmarks.forEach 50 avgt 50 191.173 ± 0.570 ns/op NCopiesBenchmarks.forEach:·gc.alloc.rate 50 avgt 500.001 ± 0.001 MB/sec NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 50 avgt 50 ≈ 10⁻⁴ B/op NCopiesBenchmarks.forEach:·gc.count50 avgt 50 ≈ 0 counts NCopiesBenchmarks.forEach 100 avgt 50 376.675 ± 2.476 ns/op NCopiesBenchmarks.forEach:·gc.alloc.rate 100 avgt 500.001 ± 0.001 MB/sec NCopiesBenchmarks.forEach:·gc.alloc.rate.norm 100 avgt 500.001 ± 0.001B/op NCopiesBenchmarks.forEach:·gc.count 100 avgt 50 ≈ 0 counts - Commit messages: - Implement forEach in Collections.CopiesList Changes: https://git.openjdk.java.net/jdk/pull/2524/files Webrev: https://webrevs.openjdk.java.net/?repo=jdk=2524=00 Issue: https://bugs.openjdk.java.net/browse/JDK-8274715 Stats: 15 lines in 1 file changed: 10 ins; 2 del; 3 mod Patch: https://git.openjdk.java.net/jdk/pull/2524.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/2524/head:pull/2524 PR: https://git.openjdk.java.net/jdk/pull/2524