[
https://issues.apache.org/jira/browse/HBASE-22670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16881909#comment-16881909
]
ramkrishna.s.vasudevan commented on HBASE-22670:
------------------------------------------------
Though we have the ArraysSupport#mismatch() the impl does some more steps than
what we have in compareToUnSafe(). Like ArraysSupport#vectorizedMismatch() does
{code}
long av = U.getLongUnaligned(a, aOffset + bi);
long bv = U.getLongUnaligned(b, bOffset + bi);
{code}
Than doing a Unsafe#getLong() asin compareToUnsafe().
Also the mismatch() API gives you the index where the mismatch happens but the
compareToUnsafe() directly returns the comparator output.
The ArraysSupport#mismatch() also tries to do some optimization by reading the
first bit and if there is a mismatch return there even before doing the
getLongUnaligned(). I tried copying the API's impl to the BBUtils class and
tried doing getLong() instead of getLongUnaligned() and avoided the first bit
read as done in ArraysSupport#mismatch().
The JMH results for a 27 bit row key , 3 bit family and with a 4 bit qualifier
where the qualifier alone changes, the CellCompartor#compare() with
compareToUnsafe() and mismatch() based impl are as follows
With compareToUnsafe()
{code}
Comparator.arrayBBCompare avgt 10 554.920 ± 2.085 ns/op
Comparator.arrayCompare avgt 10 494.358 ± 8.810 ns/op
Comparator.bbArrayCompare avgt 10 539.219 ± 5.260 ns/op
Comparator.bbCompare avgt 10 220.743 ± 11.723 ns/op
{code}
With ArraysSupport#mismatch() based impl
{code}
Benchmark Mode Cnt Score Error Units
Comparator.arrayBBCompare avgt 10 511.787 ± 6.902 ns/op
Comparator.arrayCompare avgt 10 440.026 ± 17.410 ns/op
Comparator.bbArrayCompare avgt 10 510.578 ± 1.209 ns/op
Comparator.bbCompare avgt 10 274.158 ± 1.975 ns/op
{code}
Basically we don't get a significant difference here.
> JDK 11 and CellComparator
> -------------------------
>
> Key: HBASE-22670
> URL: https://issues.apache.org/jira/browse/HBASE-22670
> Project: HBase
> Issue Type: Improvement
> Affects Versions: 3.0.0
> Reporter: ramkrishna.s.vasudevan
> Assignee: ramkrishna.s.vasudevan
> Priority: Major
>
> This could act as a parent JIRA for analysing JDK 11 and the Comparator impls
> that we have.
> Latest JDK has support for SIMD and AVX512, which means it has support for
> vectorizations.
> See JDK11's ArraysSupport#mismatch() and vectorizedMismatch().
> We also have BufferMismatch#mismatch() which is not publicly exposed but it
> uses the ArraysSupport#vectorizedMismatch().
> Internally vectorizedMismatch() does something similar to what
> UnsafeComparator#compareToUnsafe does. Will add about the details of the
> study in further comments.
> The JDK also exposes new annotations like @HotSpotIntrinsicCandidate and
> @ForceInline tags that helps in inlining the intrinsic calls.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)