fast-uuid
fast-uuid copied to clipboard
Use JDK UUID#fromString for Java >= 15
Explanation on the README
Java 8
Benchmark Mode Cnt Score Error Units
UUIDBenchmark.benchmarkFastParserToString thrpt 3 29072210.194 ± 1272384.932 ops/s
UUIDBenchmark.benchmarkUUIDToString thrpt 3 3919194.916 ± 3994770.461 ops/s
Benchmark Mode Cnt Score Error Units
UUIDBenchmark.benchmarkUUIDFromCharSequenceFastParser thrpt 3 26652839.180 ± 42300562.510 ops/s
UUIDBenchmark.benchmarkUUIDFromFastParser thrpt 3 28014259.927 ± 14211646.057 ops/s
UUIDBenchmark.benchmarkUUIDFromString thrpt 3 2140616.212 ± 3066552.678 ops/s
Java 17
Benchmark Mode Cnt Score Error Units
UUIDBenchmark.benchmarkFastParserToString thrpt 3 45713487.632 ± 7374721.402 ops/s
UUIDBenchmark.benchmarkUUIDToString thrpt 3 46517026.066 ± 25676934.756 ops/s
Benchmark Mode Cnt Score Error Units
UUIDBenchmark.benchmarkUUIDFromCharSequenceFastParser thrpt 3 35336973.563 ± 2908998.623 ops/s
UUIDBenchmark.benchmarkUUIDFromFastParser thrpt 3 33821627.866 ± 3319481.493 ops/s
UUIDBenchmark.benchmarkUUIDFromString thrpt 3 32269917.127 ± 27127704.981 ops/s
Java 17 (before this change):
Benchmark Mode Cnt Score Error Units
UUIDBenchmark.benchmarkFastParserToString thrpt 3 44798986.151 ± 8939223.200 ops/s
UUIDBenchmark.benchmarkUUIDToString thrpt 3 44832192.867 ± 7551885.052 ops/s
Benchmark Mode Cnt Score Error Units
UUIDBenchmark.benchmarkUUIDFromCharSequenceFastParser thrpt 3 31220499.311 ± 3755386.722 ops/s
UUIDBenchmark.benchmarkUUIDFromFastParser thrpt 3 31234004.484 ± 2334153.214 ops/s
UUIDBenchmark.benchmarkUUIDFromString thrpt 3 35230981.215 ± 9501357.140 ops/s
I would second this. Comparing the actual Open JDK 17 implementation with the FastUUID implementation, I see only small differences. As such, I would recommend people to use the build-in version instead.
Perhaps you should go even one step further, and you should declare this utility 'deprecated' for OpenJDK 17 onward.
@KevinAtSesam deprecated for OpenJDK >= 15, though for the foreseeable future, I think projects will still be targeting Java 8 or 11, so this is still a pretty useful library.
@KevinAtSesam also, this library can handle any CharSequence whereas with JDK you'd only be able to handle String, so you'd either have to convert the CharSequence to a String, meaning copying its contents (if it's not a String already).
I mean, pretty minor use-case, though, but still a difference.
Sounds good to me. Just glad to see that Jdk 17 made such an improvement.
Thank you for the contribution! I have a couple questions and suggestions, but agree that this is a good thing to be doing in general.
One additional request that doesn't fit neatly on any single line of code: since we're making Java 15 the cutoff for some of these features, could you please share benchmarks form Java 15? (EDIT: to be clear, I really appreciate the benchmark results from Java 17, but matching the benchmarks to the cutoff version would be great for posterity!)
Thanks very much!
Sure. Will get benchmarks from 15 later today.
@jchambers
Java 15 (AdoptOpenJDK HotSpot)
Benchmark Mode Cnt Score Error Units
UUIDBenchmark.benchmarkFastParserToString thrpt 3 31602194.038 ± 3833604.315 ops/s
UUIDBenchmark.benchmarkUUIDFromFastParser thrpt 3 26991706.481 ± 3713708.753 ops/s
UUIDBenchmark.benchmarkUUIDFromString thrpt 3 33169614.473 ± 4664825.488 ops/s
UUIDBenchmark.benchmarkUUIDToString thrpt 3 42468946.506 ± 718697.780 ops/s
Thank you for the Java 15 benchmarks! Let's resolve the conversation about the String/CharSequence thing, then figure out next steps from there.
@jchambers so, any news on that?
Oops—sorry. This got lost in the holiday shuffle. I'll get back to this shortly.
@jchambers hi there :) wanna figure out the situation with the CharSequence stuff?
I can also add the GCProfiler to the benchmark methods so we can have the garbage data as well, but IIRC none of the methods create much garbage anyway.