RFR: 8311864: Add ArraysSupport.hashCode(int[] a, fromIndex, length, initialValue)

Glavo duke at openjdk.org
Thu Jul 13 14:49:20 UTC 2023


On Thu, 13 Jul 2023 09:27:03 GMT, Pavel Rappo <prappo at openjdk.org> wrote:

> > @pavelrappo Actually I look at the implementation of `ArraySupport.vectorizedHashCode` and it does branching and only uses vector instructions if the length is sufficiently large. Please do benchmarking if you are uncertain with performance characteristics of functions. Thanks.
> 
> Are you sure you are talking about `vectorizedHashCode` and not `vectorizedMismatch`? While the latter indeed branches on array length, the former consists of simple for-loops, which might not be the actual thing anyway because the whole method is `@IntrinsicCandidate`.
> 
> Regardless of any performance characteristics, the call to something named `vectorizedHashCode` might needlessly draw attention to something that does not deserve it.
> 
> My mental model might be wrong, but let me give you a stream analogy. Would you not pause and think if you unexpectedly saw this?
> 
> ```
> ...
> .stream()
> ...
> .parallel()
> ...
> ```

I don't think it's a good analogy. In my understanding, it is an obvious fact that `vectorizedHashCode` will not always vectorize, as vectorized code must always handle suffixes that cannot be vectorized.

I don't think judging outside `vectorizedHashCode` will make the code clear, unless `vectorizedHashCode` only handles the part that can be vectorized, and the processing of suffixes is also outside `vectorizedHashCode`.

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

PR Comment: https://git.openjdk.org/jdk/pull/14831#issuecomment-1634378224


More information about the core-libs-dev mailing list