RFR: 8310502 : optimization for UUID#toString

Alan Bateman alanb at openjdk.org
Wed Jun 21 08:01:05 UTC 2023


On Wed, 21 Jun 2023 07:28:54 GMT, 温绍锦 <duke at openjdk.org> wrote:

> By optimizing the implementation of java.lang.Long#fastUUID, the performance of the java.util.UUID#toString method can be significantly improved.
> 
> The following are the test results of JMH: 
> 
> Benchmark                     Mode  Cnt      Score      Error   Units
> UUIDUtilsBenchmark.new       thrpt    5  92676.550 ±  292.213  ops/ms
> UUIDUtilsBenchmark.original  thrpt    5  37040.165 ± 1023.532  ops/ms

src/java.base/share/classes/java/lang/Long.java line 97:

> 95:                     + (lo < 10 ? '0' + lo : 'a' + lo - 10));
> 96:         }
> 97:     }

Are you checking the impact on startup? I guess I would have expected to see it loaded from the CDS archive. Given that the usage is just UUID::toString then maybe you could move this to a holder class containing a Stable array, at least until there is a better way to have lazily computed constants. Another thing to try is moving fastUUID out of Long - moving to an array of precomputed hex values means it is not tied to Long internals anymore.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14578#discussion_r1236556426


More information about the core-libs-dev mailing list