RFR: 8196334: Optimize UUID#fromString
peter.levart at gmail.com
Sun Mar 8 11:46:22 UTC 2020
When I noticed this optimization, I had some ideas how to push this even
further, but only now had some time to try them out.
Here are some incremental improvements  to the already brilliant idea
with the following JMH results (the baseline is JDK build with patch for
8196334 already applied):
Benchmark (size) Mode Cnt Score Error Units
UUIDBench.uuidFromString 20000 thrpt 5 37.344 ± 0.257 ops/us
UUIDBench.uuidFromStringAlt1 20000 thrpt 5 29.069 ± 0.137 ops/us
UUIDBench.uuidFromStringAlt2 20000 thrpt 5 27.308 ± 0.204 ops/us
UUIDBench.uuidFromStringAlt3 20000 thrpt 5 23.195 ± 0.885 ops/us
As can be seen, the trick was to eliminate branches (alt1, alt2) and to
reduce the number of operations (shifts) in alt3. One last trick in alt3
was to use the array length in a check that is then fused with array
index bounds check (I think) so that we get one of them for free.
What do you think? Is this good enough to warrant another change? As you
can see, I haven't prepared the patch yet, just benchmark.
On 3/2/20 8:26 AM, Claes Redestad wrote:
> On 2020-03-02 08:14, Alan Bateman wrote:
>> Looks good.
> Thanks - pushed!
More information about the core-libs-dev