Michael, Thanks. This may be tricky. isArray is a native method, and we don't want to pay for native method overhead - we're depending on hotspot intrinsification. I suspect isArray will lose with -Xint and perhaps also with C1. In the hotspot sources I see an ominous virtual bool is_array_klass_slow(). Perhaps other engineers can give an authoritative recommendation on which way to go.
On Wed, May 2, 2018 at 1:51 PM, Michael Rasmussen < michael.rasmus...@roguewave.com> wrote: > Hi Martin, > > > Did you consider using Class::isArray in the loop? Something like > the following: > > for (Object element : a) { > final int elementHash; > if (element == null) { > elementHash = 0; > } > else { > final Class<?> cl = element.getClass(); > if (!cl.isArray()) > elementHash = element.hashCode(); > else if (element instanceof Object[]) > elementHash = deepHashCode((Object[]) element); > else > elementHash = primitiveArrayHashCode(element, > cl.getComponentType()); > } > > result = 31 * result + elementHash; > } > > In my quick JMH test running on Java 10, it improved the performance > with your test array (Object[100000] full of Integers) from 244 us/op to > 160 us/op (vs current JDK: 399 us/op). > > > /Michael > ------------------------------ > *From:* core-libs-dev <core-libs-dev-boun...@openjdk.java.net> on behalf > of Martin Buchholz <marti...@google.com> > *Sent:* 02 May 2018 21:17:19 > *To:* Paul Sandoz > *Cc:* core-libs-dev > *Subject:* Re: RFR: Here are some easy patches > > Hi Paul, > > On Mon, Apr 30, 2018 at 2:03 PM, Paul Sandoz <paul.san...@oracle.com> > wrote: > > > > > > > On Apr 30, 2018, at 11:18 AM, Martin Buchholz <marti...@google.com> > wrote: > > > > > > > > On Mon, Apr 30, 2018 at 10:35 AM, Paul Sandoz <paul.san...@oracle.com> > > wrote: > > > >> An obvious optimization: > >> > >> 8202398: Optimize Arrays.deepHashCode > >> http://cr.openjdk.java.net/~martin/webrevs/jdk/deepHashCode-optimize/ > >> https://bugs.openjdk.java.net/browse/JDK-8202398 > >> > >> I would prefer that the deeply nested ternary expressions be changed to > a > >> more expected if/else if/else > >> > > > > My brain much prefers code transforming tabular data to "look tabular". > > > > > > > > I think you will like expression switch :-) in the interim i would stick > > with the less eyebrow raising syntax. > > > > > I'm going to claim committer's privilege and check in with my preferred > tabular style. You can rewrite using suburban sprawl style when us > dinosaurs from the last milllenium have gone extinct. >