Skip to content

Add JMH benchmark proving direct Math.multiplyHigh path outperforms invokeExact#117

Merged
peter-lawrey merged 1 commit into
developfrom
feature/multiplyHigh
Apr 28, 2026
Merged

Add JMH benchmark proving direct Math.multiplyHigh path outperforms invokeExact#117
peter-lawrey merged 1 commit into
developfrom
feature/multiplyHigh

Conversation

@peter-lawrey

@peter-lawrey peter-lawrey commented Apr 28, 2026

Copy link
Copy Markdown
Member

This PR adds a JMH benchmark for XXH3 hashing of a 128-byte array and switches the Java 9+ multiplication path from reflective MethodHandle.invokeExact(...) to a direct Math.multiplyHigh(...) call enabled by the Java 8 compile-time stub.

Why

The previous Java 9+ path used reflection plus MethodHandle.invokeExact(...) so the project could still compile for Java 8. That avoided a hard Java 9 API dependency, but it also prevented the hot multiplication path from being as efficiently optimised and inlined as a normal Math.multiplyHigh(...) call.

This change keeps Java 8 compilation support while allowing newer JVMs to call Math.multiplyHigh(...) naturally.

What changed

  • Added JMH test dependencies.
  • Added XXH3HashBytesBenchmark covering XXH3 hashing of a 128-byte array, reproducing issue Performance degradation between 0.16 and 0.27ea1 #101.
  • Replaced the MethodHandle.invokeExact(...) path in MathsJDK9 with direct Math.multiplyHigh(...) calls.
  • Retained runtime fallback to the scalar Java 8 implementation when Math.multiplyHigh(...) is unavailable.
  • Added SonarCloud project properties.

Expected benefit

On Java 9+ runtimes, XXH3 can now use the JVM-recognised Math.multiplyHigh(...) path directly, making it eligible for normal JIT optimisation/inlining instead of paying the invokeExact(...) overhead in the hashing hot path.

@peter-lawrey peter-lawrey changed the title Implement support for Math.multiplyHigh in Maths class and add JMH be… Add JMH benchmark proving direct Math.multiplyHigh path outperforms invokeExact Apr 28, 2026
@peter-lawrey peter-lawrey requested a review from tgd April 28, 2026 10:33
@tgd tgd changed the base branch from ea to develop April 28, 2026 13:12
@sonarqubecloud

Copy link
Copy Markdown

@peter-lawrey peter-lawrey merged commit 02331d9 into develop Apr 28, 2026
10 of 11 checks passed
@peter-lawrey peter-lawrey deleted the feature/multiplyHigh branch April 28, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants