RFR: 8311207: Optimization for j.u.UUID.toString
温绍锦
duke at openjdk.org
Sat Jul 1 02:39:53 UTC 2023
On Sat, 1 Jul 2023 02:09:36 GMT, Chen Liang <liach 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
> 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
> 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
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14745#issuecomment-1615378812
PR Review Comment: https://git.openjdk.org/jdk/pull/14745#discussion_r1248397231
PR Review Comment: https://git.openjdk.org/jdk/pull/14745#discussion_r1248397251
More information about the core-libs-dev
mailing list