Add JMH benchmark proving direct Math.multiplyHigh path outperforms invokeExact#117
Merged
Conversation
…nchmarking for XXH3 hashing
Math.multiplyHigh path outperforms invokeExact
tgd
approved these changes
Apr 28, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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 directMath.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 normalMath.multiplyHigh(...)call.This change keeps Java 8 compilation support while allowing newer JVMs to call
Math.multiplyHigh(...)naturally.What changed
XXH3HashBytesBenchmarkcovering XXH3 hashing of a 128-byte array, reproducing issue Performance degradation between 0.16 and 0.27ea1 #101.MethodHandle.invokeExact(...)path inMathsJDK9with directMath.multiplyHigh(...)calls.Math.multiplyHigh(...)is unavailable.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 theinvokeExact(...)overhead in the hashing hot path.