charlesconnell commented on PR #8757: URL: https://github.com/apache/hbase/pull/8757#issuecomment-6319786841
@ndimiduk gave me the idea of running the same benchmark on Java 25. This makes the performance difference between Unsafe and VarHandle basically go away! Results from using temurinjdk25.0.4.1+1 on the same m8i.large and m8g.large machines: x86: ``` Benchmark (contents) (direct) (length) Mode Cnt Score Error Units ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 13 thrpt 25 185.792 ± 2.938 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 64 thrpt 25 187.055 ± 4.083 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 255 thrpt 25 65.684 ± 1.121 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 1024 thrpt 25 30.423 ± 0.605 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 4099 thrpt 25 8.473 ± 0.186 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 13 thrpt 25 212.966 ± 5.636 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 64 thrpt 25 215.895 ± 5.488 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 255 thrpt 25 68.522 ± 1.616 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 1024 thrpt 25 31.539 ± 0.592 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 4099 thrpt 25 7.177 ± 0.143 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 13 thrpt 25 436.213 ± 6.255 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 64 thrpt 25 281.579 ± 6.314 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 255 thrpt 25 150.797 ± 2.887 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 1024 thrpt 25 54.240 ± 0.911 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 4099 thrpt 25 15.495 ± 0.287 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 13 thrpt 25 534.511 ± 10.956 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 64 thrpt 25 310.391 ± 8.656 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 255 thrpt 25 154.591 ± 3.311 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 1024 thrpt 25 54.506 ± 0.977 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 4099 thrpt 25 14.483 ± 1.439 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 13 thrpt 25 177.197 ± 2.928 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 64 thrpt 25 141.886 ± 3.433 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 255 thrpt 25 65.563 ± 1.361 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 1024 thrpt 25 29.827 ± 0.660 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 4099 thrpt 25 8.284 ± 0.165 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 13 thrpt 25 199.083 ± 4.435 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 64 thrpt 25 148.368 ± 2.935 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 255 thrpt 25 71.222 ± 1.304 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 1024 thrpt 25 30.822 ± 0.626 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 4099 thrpt 25 8.894 ± 0.135 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 13 thrpt 25 387.334 ± 7.735 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 64 thrpt 25 219.787 ± 4.632 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 255 thrpt 25 127.702 ± 2.090 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 1024 thrpt 25 51.958 ± 1.465 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 4099 thrpt 25 15.259 ± 0.262 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 13 thrpt 25 413.296 ± 9.148 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 64 thrpt 25 230.373 ± 6.186 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 255 thrpt 25 139.942 ± 3.892 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 1024 thrpt 25 54.106 ± 0.997 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 4099 thrpt 25 15.336 ± 0.218 ops/us ``` arm64: ``` Benchmark (contents) (direct) (length) Mode Cnt Score Error Units ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 13 thrpt 25 167.833 ± 0.685 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 64 thrpt 25 171.808 ± 2.328 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 255 thrpt 25 60.307 ± 0.397 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 1024 thrpt 25 23.280 ± 0.037 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL false 4099 thrpt 25 6.391 ± 0.024 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 13 thrpt 25 228.809 ± 1.211 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 64 thrpt 25 206.331 ± 2.983 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 255 thrpt 25 63.602 ± 0.602 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 1024 thrpt 25 23.312 ± 0.242 ops/us ByteBufferCompareBenchmark.unsafeGetLong EQUAL true 4099 thrpt 25 6.390 ± 0.021 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 13 thrpt 25 422.962 ± 8.943 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 64 thrpt 25 260.930 ± 1.517 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 255 thrpt 25 121.303 ± 0.466 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 1024 thrpt 25 41.213 ± 0.794 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE false 4099 thrpt 25 12.314 ± 0.061 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 13 thrpt 25 565.944 ± 3.278 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 64 thrpt 25 289.640 ± 6.418 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 255 thrpt 25 133.937 ± 0.486 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 1024 thrpt 25 42.319 ± 0.159 ops/us ByteBufferCompareBenchmark.unsafeGetLong MISMATCH_MIDDLE true 4099 thrpt 25 12.365 ± 0.081 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 13 thrpt 25 185.034 ± 0.853 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 64 thrpt 25 163.232 ± 3.449 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 255 thrpt 25 62.297 ± 1.009 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 1024 thrpt 25 23.153 ± 0.022 ops/us ByteBufferCompareBenchmark.varHandle EQUAL false 4099 thrpt 25 6.378 ± 0.011 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 13 thrpt 25 197.691 ± 0.517 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 64 thrpt 25 166.763 ± 0.933 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 255 thrpt 25 64.927 ± 0.208 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 1024 thrpt 25 23.267 ± 0.210 ops/us ByteBufferCompareBenchmark.varHandle EQUAL true 4099 thrpt 25 6.355 ± 0.014 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 13 thrpt 25 401.683 ± 4.646 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 64 thrpt 25 228.333 ± 2.359 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 255 thrpt 25 120.131 ± 1.366 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 1024 thrpt 25 40.486 ± 0.228 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE false 4099 thrpt 25 12.300 ± 0.033 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 13 thrpt 25 449.787 ± 12.287 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 64 thrpt 25 236.565 ± 2.055 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 255 thrpt 25 124.090 ± 0.351 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 1024 thrpt 25 41.558 ± 0.132 ops/us ByteBufferCompareBenchmark.varHandle MISMATCH_MIDDLE true 4099 thrpt 25 12.332 ± 0.128 ops/us ``` And now the comparison table again: | Arch | Contents | Direct | 13 | 64 | 255 | 1024 | 4099 | |-------|-----------------|--------|------|------|------|------|------| | x86 | EQUAL | false | 1.05 | 1.32 | 1.00 | 1.02 | 1.02 | | x86 | EQUAL | true | 1.07 | 1.46 | 0.96 | 1.02 | 0.81 | | x86 | MISMATCH_MIDDLE | false | 1.13 | 1.28 | 1.18 | 1.04 | 1.02 | | x86 | MISMATCH_MIDDLE | true | 1.29 | 1.35 | 1.10 | 1.01 | 0.94 | | arm64 | EQUAL | false | 0.91 | 1.05 | 0.97 | 1.01 | 1.00 | | arm64 | EQUAL | true | 1.16 | 1.24 | 0.98 | 1.00 | 1.01 | | arm64 | MISMATCH_MIDDLE | false | 1.05 | 1.14 | 1.01 | 1.02 | 1.00 | | arm64 | MISMATCH_MIDDLE | true | 1.26 | 1.22 | 1.08 | 1.02 | 1.00 | VarHandle's code doesn't change from OpenJDK 21 to 25, so the difference must come from the JIT. My AI suggested it might be [JDK-8343685](https://bugs.openjdk.org/browse/JDK-8343685), which seems plausible to me. Overall, this is great news, because it means there is a way to switch to VarHandle without any performance hit. -- 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]
