RFR: 8312424: 80% throughput decrease in Arrays.hashCode(Object[]) after JDK-8312164
Glavo
duke at openjdk.org
Thu Jul 20 01:34:52 UTC 2023
On Thu, 20 Jul 2023 01:11:43 GMT, Glavo <duke at openjdk.org> wrote:
> The changes to `Arrays.hashCode(Object[])` in JDK-8312164 caused its performance is reduced by about 80%.
>
> This PR reverts this change.
JMH Benchmark:
public class HashCode {
@Param({"1", "10", "100", "10000"})
private int size;
private Object[] objects;
@Setup
public void setup() {
objects = new Object[size];
Random rnd = new Random(0);
for (int i = 0; i < size; i++) {
int next = rnd.nextInt();
objects[i] = next;
}
}
@Benchmark
public int objects() {
return Arrays.hashCode(objects);
}
}
(JDK-8312164) (This PR)
Benchmark (size) Mode Cnt Score Error Units Score Error Units
HashCode.objects 1 thrpt 5 230185.853 ± 3452.863 ops/ms 646049.006 ± 3964.138 ops/ms
HashCode.objects 10 thrpt 5 25745.466 ± 38.342 ops/ms 121587.901 ± 1114.723 ops/ms
HashCode.objects 100 thrpt 5 2558.474 ± 21.726 ops/ms 11914.620 ± 233.365 ops/ms
HashCode.objects 10000 thrpt 5 27.592 ± 0.116 ops/ms 125.938 ± 0.145 ops/ms
> 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.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14944#issuecomment-1642962527
PR Comment: https://git.openjdk.org/jdk/pull/14944#issuecomment-1642971201
More information about the core-libs-dev
mailing list