RFR: 8311207: Optimization for j.u.UUID.toString

Chen Liang liach at openjdk.org
Sat Jul 1 02:39:54 UTC 2023


On Sat, 1 Jul 2023 02:33:11 GMT, 温绍锦 <duke at openjdk.org> wrote:

> > Is using `Unsafe` directly consistently faster than using ByteArray? It should have similar performance as ByteArray's VarHandle is simply a wrapper around Unsafe's put/get methods.
> 
> Using Unsafe on aliyun_ecs_c8i.xlarge and MacBookPro M1 Pro is faster than ByteArray, and I haven't figured out why

Then it's probably VarHandle's overhead. No worries; your change to use Unsafe is totally fine.

Meanwhile, can you enable GitHub actions on your fork, so it can detect compile and test errors? Like this:
<img width="1259" alt="image" src="https://github.com/openjdk/jdk/assets/7806504/fa843978-757c-4ba0-a23f-055f25ddda7e">

>> src/java.base/share/classes/java/util/HexDigits.java line 108:
>> 
>>> 106:      * Combine two hex shorts into one int based on big endian
>>> 107:      */
>>> 108:     static int packDigits(int b0, int b1) {
>> 
>> I recommend such a refactor:
>> 
>> /**
>>  * Return a big-endian packed integer for the 4 ASCII bytes for an input unsigned short value.
>>  */
>> static int packDigits16(int b) {
>>     return (DIGITS[(b >> 8) & 0xff] << 16) | DIGITS[b & 0xff];
>> }
>> 
>> And all your usages can be `HexDigits.packDigits16(((int) msb) >> 16)` and `HexDigits.packDigits16((int) msb)` without the `>> 24` and `>> 8`
>
> but it's return an int value

The current code snippet still returns a int value... I think I can probably make a patch and demonstrate.

>> src/java.base/share/classes/java/util/HexDigits.java line 115:
>> 
>>> 113:      * Combine four hex shorts into one long based on big endian
>>> 114:      */
>>> 115:     static long packDigits(int b0, int b1, int b2, int b3) {
>> 
>> Same comment here:
>> 
>> 
>> /**
>>  * Return a big-endian packed long for the 8 ASCII bytes for an input unsigned int value.
>>  */
>> static long packDigits32(int b) {
>>     return (((long) DIGITS[(b >> 24) & 0xff]) << 48)
>>             | (((long) DIGITS[(b >> 16) & 0xff]) << 32)
>>             | (DIGITS[(b >> 8) & 0xff] << 16)
>>             | DIGITS[b & 0xff];
>> }
>> 
>> And use sites become:
>> 
>> // old
>> HexDigits.packDigits((int) (msb >> 56), (int) (msb >> 48), (int) (msb >> 40), (int) (msb >> 32))
>> // new
>> HexDigits.packDigits32((int) (msb >> 32))
>> 
>> and `HexDigits.packDigits32((int) (lsb >> 16))`
>
> but it's return a long value

My fault, fixed the return type in my code snippet.

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

PR Comment: https://git.openjdk.org/jdk/pull/14745#issuecomment-1615379558
PR Review Comment: https://git.openjdk.org/jdk/pull/14745#discussion_r1248397625
PR Review Comment: https://git.openjdk.org/jdk/pull/14745#discussion_r1248397481


More information about the core-libs-dev mailing list