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

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


On Sat, 1 Jul 2023 01:44:15 GMT, 温绍锦 <duke at openjdk.org> wrote:

> [PR 14578 ](https://github.com/openjdk/jdk/pull/14578) still has unresolved discussions, continue to make improvements.
> 
> # Benchmark Result
> 
> 
> sh make/devkit/createJMHBundle.sh
> bash configure --with-jmh=build/jmh/jars
> make test TEST="micro:java.util.UUIDBench.toString"
> 
> 
> ## 1. [aliyun_ecs_c8i.xlarge](https://help.aliyun.com/document_detail/25378.html#c8i)
> * cpu : intel xeon sapphire rapids (x64)
> 
> ``` diff
> -Benchmark           (size)   Mode  Cnt   Score   Error   Units (baseline)
> -UUIDBench.toString   20000  thrpt   15  62.019 ± 0.622  ops/us
> 
> +Benchmark           (size)   Mode  Cnt   Score   Error   Units
> +UUIDBench.toString   20000  thrpt   15  82.998 ± 0.739  ops/us (+33.82%)
> 
> 
> ## 2. [aliyun_ecs_c8a.xlarge](https://help.aliyun.com/document_detail/25378.html#c8a)
> * cpu : amd epc genoa (x64)
> 
> ``` diff
> -Benchmark           (size)   Mode  Cnt   Score   Error   Units (baseline)
> -UUIDBench.toString   20000  thrpt   15  88.668 ± 0.672  ops/us
> 
> +Benchmark           (size)   Mode  Cnt   Score   Error   Units
> +UUIDBench.toString   20000  thrpt   15  89.229 ± 0.271  ops/us (+0.63%)
> 
> 
> 
> ## 3. [aliyun_ecs_c8y.xlarge](https://help.aliyun.com/document_detail/25378.html#c8y)
> * cpu : aliyun yitian 710 (aarch64)
> ``` diff
> -Benchmark           (size)   Mode  Cnt   Score   Error   Units (baseline)
> -UUIDBench.toString   20000  thrpt   15  49.382 ± 2.160  ops/us
> 
> +Benchmark           (size)   Mode  Cnt   Score   Error   Units
> +UUIDBench.toString   20000  thrpt   15  49.636 ± 1.974  ops/us (+0.51%)
> 
> 
> ## 4. MacBookPro M1 Pro
> ``` diff
> -Benchmark           (size)   Mode  Cnt    Score   Error   Units (baseline)
> -UUIDBench.toString   20000  thrpt   15  103.543 ± 0.963  ops/us
> 
> +Benchmark           (size)   Mode  Cnt    Score   Error   Units
> +UUIDBench.toString   20000  thrpt   15  110.976 ± 0.685  ops/us (+7.17%)
> 
> 
> ## 5. Orange Pi 5 Plus
> 
> ``` diff
> -Benchmark           (size)   Mode  Cnt   Score   Error   Units (baseline)
> -UUIDBench.toString   20000  thrpt   15  33.532 ± 0.396  ops/us
> 
> +Benchmark           (size)   Mode  Cnt   Score   Error   Units (PR)
> +UUIDBench.toString   20000  thrpt   15  33.054 ± 0.190  ops/us (-4.42%)

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`

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))`

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14745#discussion_r1248389049
PR Review Comment: https://git.openjdk.org/jdk/pull/14745#discussion_r1248394179


More information about the core-libs-dev mailing list