Hash64: hybrid inline/getBytes UTF-8 path in updateString#1236
Merged
Conversation
Replaces the previous single-path updateString with a length-based hybrid: - For length ≤ 128 (typical metric tag values) or any non-String CharSequence: inline UTF-8 char loop, no allocation, no per-call encoder setup overhead. - For longer String inputs: fall back to getBytes(UTF_8) + Unsafe long-stride updateBytes, where the intrinsified UTF-8 encoder and 8-byte-per-iter writes win on throughput. Output is bit-identical to updateBytes(s.getBytes(UTF_8)) regardless of which path is taken; the existing Hash64Test.checkString assertions cover both sides of the threshold (random strings of length 0-999). Other changes: - New private writeByte helper handles per-byte stripe writes and rollover; updateByte delegates to it to avoid duplicate logic. - build.gradle: pin the jmh task to JDK 25 so benchmarks reflect the modern JIT, independent of the JDK 8 source toolchain. JMH on JDK 25 (M1; see IdHash.java javadoc for the full table): IdHash.hash64 1.25M -> 2.05M ops/s (+64%) IdHash.shortAsciiString 20M -> 22M (+13%) IdHash.unicodeString 12M -> 14M (+19%) IdHash.longAsciiString 4.15M -> 4.20M (+1%) IdHash.hash64_2 2.98M -> 2.73M (-9%)
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.
Replaces the previous single-path updateString with a length-based hybrid:
Output is bit-identical to updateBytes(s.getBytes(UTF_8)) regardless of which path is taken; the existing Hash64Test.checkString assertions cover both sides of the threshold (random strings of length 0-999).
Other changes:
JMH on JDK 25 (M1; see IdHash.java javadoc for the full table):