[ 
https://issues.apache.org/jira/browse/HBASE-28025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17755667#comment-17755667
 ] 

Becker Ewing commented on HBASE-28025:
--------------------------------------

Thank you for the review [~zhangduo]! 

 

*Benchmarking Methodology*

I've done some benchmarking of the normal java implementation vs. the optimized 
unsafe implementation across various buffer/array types and key sizes. The test 
methodology was for each key size (2, 36, 135) generate buffers & arrays with 
identical contents that differ only in the last byte. Call findCommonPrefix for 
every possible buffer/array combination on both the pure java implementation 
and the unsafe implementation. My environment is: JMH 1.37, JVM: JDK 11.0.12, 
OpenJDK 64-Bit Server VM, 11.0.12+7, CPU: Apple M1 Max. Benchmarks were run by 
compiling the attached source and running it.

 

*Raw Data*
||Benchmark Name||Key Size||Pure Java Implementation Average Time 
(ns/op)||Unsafe Implementation Average Time (ns/op)||
|findCommonPrefix_Array_Array|2|4.170 ±  0.122|4.698 ±  0.104|
| |36|14.971 ±  0.631|8.702 ±  0.167|
| |135|39.706 ±  3.025|14.968 ±  0.316|
|findCommonPrefix_OffHeapBB_Array|2|4.378 ±  0.173|4.198 ±  0.285|
| |36|19.554 ±  0.312|7.563 ±  0.053|
| |135|60.766 ±  5.392|13.639 ±  0.189|
|findCommonPrefix_OffHeapBB_OffHeapBB|2|4.499 ±  0.401|4.882 ±  0.137|
| |36|22.649 ±  0.574|7.947 ±  0.183|
| |135|72.753 ±  2.831|12.699 ±  0.121|
|findCommonPrefix_OnHeapBB_OnHeapBB|2|7.626 ±  0.128|7.642 ±  0.333|
| |36|26.966 ±  0.201|12.177 ±  0.632|
| |135|114.375 ±  8.032|18.104 ±  0.629|

 

*Summary*

The new implementation is seems to be about equal or slightly slower when using 
a keySize of 2. As key size increases (particularly gets larger than 8), 
performance rapidly increases for the newer Unsafe variant of the code. It's 
about ~70% faster at a keySize of 36 and ~260% faster at a keySize of 135. 

> Enhance ByteBufferUtils.findCommonPrefix to compare 8 bytes each time
> ---------------------------------------------------------------------
>
>                 Key: HBASE-28025
>                 URL: https://issues.apache.org/jira/browse/HBASE-28025
>             Project: HBase
>          Issue Type: Improvement
>          Components: Performance
>    Affects Versions: 2.5.4
>            Reporter: Becker Ewing
>            Assignee: Becker Ewing
>            Priority: Major
>         Attachments: HBASE-28025_jmh_benchmarks_src.zip, benchmark_results.txt
>
>
> Currently, the `ByteBufferUtils.findCommonPrefix family of methods compare 
> two buffers a single byte at a time. In reviewing the patch for HBASE-28012, 
> [~zhangduo] suggested that the ByteBufferUtils.findCommonPrefix methods could 
> be enhanced to compare 8 bytes at a time like the 
> ByteBufferUtils.compareToUnsafe family of methods already does (which was 
> added in HBASE-12345)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to