@cowtowncoder

Sep 14, 2021

4 min read

Measuring performance of Java UUID.fromString() (or lack thereof)

aka “Why is UUID.fromString() so slow?”

Background

UUID uuid = UUID.fromString(request.getParameter("uuid"));

#include <std-disclaimers.h>

Does JUG have it? How about Jackson?

UUID uid = UUIDUtil.uuid(uuidString);

Test Case & Results, initial

Benchmark                     Mode   Cnt      Score       Error  Units
UUIDFromString.m1_JDK thrpt 15 89175.229 ± 1899.754 ops/s
UUIDFromString.m2_JUG thrpt 15 490052.366 ± 35351.600 ops/s
UUIDFromString.m3_manual thrpt 15 1129569.239 ± 6054.405 ops/s
  • JDK approach can decode almost 3 million UUIDs per second (per core)
  • java-uuid-generator can decode UUIDs from Strings about 5 times as fast (15 million / sec / core)
  • copy-pasted code from Jackson can decode UUIDs from Strings over 10 times as fast (33 million / sec / core)

Results with JDK 14

Benchmark                 Mode   Cnt    Score       Error    Units
UUIDFromString.m1_JDK thrpt 15 358738.222 ± 7188.453 ops/s
UUIDFromString.m2_JUG thrpt 15 529761.948 ± 3866.240 ops/s
UUIDFromString.m3_manual thrpt 15 1181016.727 ± 4541.903 ops/s

Reasons for slowness of Java 8 / UUID.fromString()

Next Steps