JDK-8196334 : Optimize UUID#fromString
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-01-29
  • Updated: 2020-03-05
  • Resolved: 2020-03-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 15
15 b13Fixed
Related Reports
Relates :  
Description
Jon Chambers writes "Because UUID strings are of a known structure and length (32 hexadecimal digits and four dashes) and because UUIDs are exactly 128 bits in length, we know exactly how each character in a UUID string maps to bits in the parsed UUID. We always know, for example, that the first character in a UUID string maps to the four highest bits in the UUID, the second character maps to the four bits below that, and so on.

With that knowledge, we can cut out a lot of the generality and bounds-checking we'd normally expect of a string-to-number parser. I've built an implementation with that in mind: https://github.com/jchambers/fast-uuid/blob/master/src/main/java/com/eatthepath/uuid/FastUUID.java#L108.
In benchmarks ( https://github.com/jchambers/fast-uuid/blob/master/benchmark/src/main/java/com/eatthepath/UUIDBenchmark.java#L55-L63 ),
this implementation is about six times faster than the current JDK
implementation (9.0.4+11) and 14 times faster than the implementation in
1.8."

http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-January/051134.html

Some of the improvement comes from being stricter about the accepted format, thus retrofitting this to UUID#fromString will likely require maintaining the existing implementation as a fallback.
Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/acc083236275 User: redestad Date: 2020-03-02 07:22:13 +0000
02-03-2020

Analysis of JDK-8196334 showed there is an opportunity to improve Character.digit for typical numerical inputs (codePoints < 256). Not enough to get UUID#fromString to be as fast as the proposed implementation, but with wider implications (optimizes all variants of Integer.parseInt, Long.parseLong etc...)
29-01-2018