On Thu, 20 Jul 2023 02:04:53 GMT, Chen Liang <li...@openjdk.org> wrote:
>>> A similar performance decrease have been discussed here: [#14752 >>> (comment)](https://github.com/openjdk/jdk/pull/14752#discussion_r1250888931) >>> >>> Can you check whether adding `@ForceInline` on `Objects.equals` help with >>> JIT? If it helps, then I think adding `@ForceInline` might be a better >>> solution. >> >> I added `@ForceInline` on `Objects.hashCode(Object)`, but the JMH results >> did not change. > > @Glavo I have created a test case with polymorphic objects in an array: > https://github.com/liachmodded/jdk/tree/explore/arrays-hash-poly > Can you see if you can produce the same outcome on your patch, and how the > existing `Objects.equals` behave on the polymorphicObjects case? > > > Benchmark (size) Mode Cnt Score Error Units > ArraysHashCode.objects 1 avgt 15 0.770 ± 0.011 ns/op > ArraysHashCode.objects 10 avgt 15 4.704 ± 0.059 ns/op > ArraysHashCode.objects 100 avgt 15 54.610 ± 0.384 ns/op > ArraysHashCode.objects 10000 avgt 15 6053.742 ± 35.244 ns/op > > > > Benchmark (size) Mode Cnt Score Error > Units > ArraysHashCode.polymorphicObjects 1 avgt 15 0.921 ± 0.069 > ns/op > ArraysHashCode.polymorphicObjects 10 avgt 15 23.322 ± 1.076 > ns/op > ArraysHashCode.polymorphicObjects 100 avgt 15 211.325 ± 2.200 > ns/op > ArraysHashCode.polymorphicObjects 10000 avgt 15 81850.916 ± 2427.661 > ns/op @liach JMH Result: (JDK-8312164) (This PR) Benchmark (size) Mode Cnt Score Error Units Score Error Units HashCode.polymorphicObjects 1 thrpt 5 148056.877 ± 8.046 ops/ms 546370.781 ± 2682.146 ops/ms HashCode.polymorphicObjects 10 thrpt 5 21207.629 ± 39.585 ops/ms 21491.320 ± 66.698 ops/ms HashCode.polymorphicObjects 100 thrpt 5 1467.886 ± 21.025 ops/ms 1509.838 ± 11.098 ops/ms HashCode.polymorphicObjects 10000 thrpt 5 9.037 ± 0.006 ops/ms 9.123 ± 0.022 ops/ms It looks like calling `Objects.hashCode(Object)` is preventing the JIT from monomorphizing. ------------- PR Comment: https://git.openjdk.org/jdk/pull/14944#issuecomment-1643016889