charlesconnell commented on PR #8757:
URL: https://github.com/apache/hbase/pull/8757#issuecomment-6283394434

   > Can you be more precise about this? Performance has always been the 
lurking concern around this change.
   
   I've run a microbenchmark, 
[here](https://gist.github.com/charlesconnell/3be3c0de4a76abb997f8d40620b1bd6a) 
is the code, and here are the results.
   
   On AWS m8i.large (x86-64, Intel Xeon 6):
   ```
   Benchmark                                              (contents)  (direct)  
(length)   Mode  Cnt    Score    Error   Units
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
      13  thrpt   25  183.540 ±  3.411  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
      64  thrpt   25  183.861 ±  3.182  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
     255  thrpt   25   65.841 ±  1.028  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
    1024  thrpt   25   30.160 ±  0.527  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
    4099  thrpt   25    8.279 ±  1.024  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
      13  thrpt   25  211.701 ±  4.934  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
      64  thrpt   25  208.307 ±  5.055  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
     255  thrpt   25   68.761 ±  1.206  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
    1024  thrpt   25   31.619 ±  0.613  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
    4099  thrpt   25    7.891 ±  0.113  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
      13  thrpt   25  452.082 ±  8.096  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
      64  thrpt   25  262.996 ±  5.439  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
     255  thrpt   25  140.243 ±  8.577  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
    1024  thrpt   25   54.199 ±  1.282  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
    4099  thrpt   25   17.252 ±  0.300  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
      13  thrpt   25  656.122 ± 19.638  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
      64  thrpt   25  272.195 ±  5.880  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
     255  thrpt   25  153.092 ±  3.290  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
    1024  thrpt   25   53.455 ±  1.216  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
    4099  thrpt   25   15.226 ±  0.469  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
      13  thrpt   25  194.607 ±  3.918  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
      64  thrpt   25  115.891 ± 13.978  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
     255  thrpt   25   49.232 ±  1.016  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
    1024  thrpt   25   13.927 ±  0.364  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
    4099  thrpt   25    4.213 ±  0.086  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
      13  thrpt   25  169.264 ± 15.187  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
      64  thrpt   25  106.334 ±  3.650  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
     255  thrpt   25   42.295 ±  0.989  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
    1024  thrpt   25   11.301 ±  0.237  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
    4099  thrpt   25    3.611 ±  0.084  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
      13  thrpt   25  388.300 ± 24.622  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
      64  thrpt   25  184.055 ±  7.525  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
     255  thrpt   25   77.996 ±  1.115  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
    1024  thrpt   25   28.873 ±  0.475  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
    4099  thrpt   25    7.855 ±  0.347  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
      13  thrpt   25  375.372 ±  7.476  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
      64  thrpt   25  130.477 ±  3.246  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
     255  thrpt   25   76.886 ±  4.301  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
    1024  thrpt   25   26.733 ±  0.490  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
    4099  thrpt   25    6.544 ±  0.101  ops/us
   ```
   
   On AWS m8g.large (arm64, Neoverse V2):
   ```
   Benchmark                                              (contents)  (direct)  
(length)   Mode  Cnt    Score    Error   Units
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
      13  thrpt   25  172.105 ±  0.223  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
      64  thrpt   25  181.771 ±  1.361  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
     255  thrpt   25   61.114 ±  0.132  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
    1024  thrpt   25   22.745 ±  0.541  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL     false  
    4099  thrpt   25    6.384 ±  0.027  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
      13  thrpt   25  226.765 ±  1.758  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
      64  thrpt   25  218.385 ±  1.318  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
     255  thrpt   25   66.456 ±  0.476  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
    1024  thrpt   25   24.052 ±  0.181  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong                    EQUAL      true  
    4099  thrpt   25    6.425 ±  0.051  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
      13  thrpt   25  465.994 ±  2.663  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
      64  thrpt   25  227.542 ±  2.034  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
     255  thrpt   25  120.602 ±  2.190  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
    1024  thrpt   25   41.394 ±  0.198  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE     false  
    4099  thrpt   25   12.283 ±  0.077  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
      13  thrpt   25  552.654 ± 10.624  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
      64  thrpt   25  295.281 ±  3.316  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
     255  thrpt   25  133.362 ±  2.651  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
    1024  thrpt   25   42.728 ±  0.540  ops/us
   ByteBufferCompareBenchmark.unsafeGetLong          MISMATCH_MIDDLE      true  
    4099  thrpt   25   12.315 ±  0.362  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
      13  thrpt   25  193.519 ± 0.535  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
      64  thrpt   25  113.822 ± 0.469  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
     255  thrpt   25   38.797 ± 0.644  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
    1024  thrpt   25   11.585 ± 0.029  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL     false  
    4099  thrpt   25    3.134 ± 0.015  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
      13  thrpt   25  186.314 ± 1.652  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
      64  thrpt   25  122.064 ± 0.303  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
     255  thrpt   25   41.059 ± 0.292  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
    1024  thrpt   25   12.019 ± 0.172  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian            EQUAL      true  
    4099  thrpt   25    3.011 ± 0.013  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
      13  thrpt   25  390.131 ± 4.930  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
      64  thrpt   25  171.107 ± 0.154  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
     255  thrpt   25   77.484 ± 0.146  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
    1024  thrpt   25   22.297 ± 0.477  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE     false  
    4099  thrpt   25    6.031 ± 0.024  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
      13  thrpt   25  372.825 ± 0.318  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
      64  thrpt   25  161.535 ± 3.548  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
     255  thrpt   25   79.254 ± 0.984  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
    1024  thrpt   25   24.054 ± 0.212  ops/us
   ByteBufferCompareBenchmark.varHandleLittleEndian  MISMATCH_MIDDLE      true  
    4099  thrpt   25    6.262 ± 0.022  ops/us
   ```
   
   VarHandle speeds relative to Unsafe follow. Each value is Unsafe throughput 
divided by VarHandle throughput, so anything above 1.0 means Unsafe is faster. 
The number columns are buffer lengths in bytes.
   
   | Arch  | Contents        | Direct | 13   | 64   | 255  | 1024 | 4099 |
   |-------|-----------------|--------|------|------|------|------|------|
   | x86   | EQUAL           | false  | 0.94 | 1.59 | 1.34 | 2.17 | 1.97 |
   | x86   | EQUAL           | true   | 1.25 | 1.96 | 1.63 | 2.80 | 2.19 |
   | x86   | MISMATCH_MIDDLE | false  | 1.16 | 1.43 | 1.80 | 1.88 | 2.20 |
   | x86   | MISMATCH_MIDDLE | true   | 1.75 | 2.09 | 1.99 | 2.00 | 2.33 |
   | arm64 | EQUAL           | false  | 0.89 | 1.60 | 1.58 | 1.96 | 2.04 |
   | arm64 | EQUAL           | true   | 1.22 | 1.79 | 1.62 | 2.00 | 2.13 |
   | arm64 | MISMATCH_MIDDLE | false  | 1.19 | 1.33 | 1.56 | 1.86 | 2.04 |
   | arm64 | MISMATCH_MIDDLE | true   | 1.48 | 1.83 | 1.68 | 1.78 | 1.97 |
   
   
   The summary is, VarHandle is just about 2x slower than Unsafe once the 
buffer size gets large enough. Obviously this is not ideal but I think it's a 
price to pay to get the Java 25 compatibility. The extra time is spent on 
bounds checks. At very small buffer sizes the VarHandle implementation is 
slightly faster than the Unsafe one, because I added faster epilogue handling 
to the VarHandle implementation in the benchmark, and it's also in this PR. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to