On Mon, 20 Jan 2025 14:32:22 GMT, Shaojin Wen <s...@openjdk.org> wrote:
>> This PR is a resubmission after PR #21593 was rolled back, and the unsafe >> offset overflow issue has been fixed. >> >> 1) Move getChars methods of StringLatin1 and StringUTF16 to DecimalDigits to >> reduce duplication. >> >> 2) HexDigits and OctalDigits also include getCharsLatin1 and getCharsUTF16 >> >> 3) Putting these two methods into DecimalDigits can avoid the need to expose >> them in JavaLangAccess >> Eliminate duplicate code in BigDecimal >> >> 4) This PR will improve the performance of Integer/Long.toString and >> StringBuilder.append(int/long) scenarios. This is because Unsafe.putByte is >> used to eliminate array bounds checks, and of course this elimination is >> safe. In previous versions, in Integer/Long.toString and >> StringBuilder.append(int/long) scenarios, -COMPACT_STRING performed better >> than +COMPACT_STRING. This is because StringUTF16.getChars uses >> StringUTF16.putChar, which is similar to Unsafe.putChar, and there is no >> bounds check. > > Shaojin Wen has updated the pull request with a new target base due to a > merge or a rebase. The incremental webrev excludes the unrelated changes > brought in by the merge/rebase. The pull request contains 29 additional > commits since the last revision: > > - Merge remote-tracking branch 'upstream/master' into > int_get_chars_dedup_202411 > - fix comments > - use putCharUnaligned > - bug fix > - from rgiulietti > - Coding style consistency, from rgiulietti > - fix benchmark, from rgiulietti > - Coding style consistency, from rgiulietti > - fix comment > - fix comment, from @rgiulietti > - ... and 19 more: https://git.openjdk.org/jdk/compare/f24d889c...be1f88ab The performance numbers below show a significant improvement for appendWithIntLatin1 and appendWithLongLatin1. However, for appendWithIntUtf16 and appendWithLongUtf16, the performance is variable, sometimes faster and sometimes slower. This inconsistency might be due to measurement errors or other factors. ## 1. Script git remote add wenshao g...@github.com:wenshao/jdk.git git fetch wenshao # baseline d9e4383cca7 git checkout d9e4383cca77ed9667ea6916624f6416f976e3bf make test TEST="micro:java.lang.StringBuilders.appendWithIntUtf16" make test TEST="micro:java.lang.StringBuilders.appendWithLongUtf16" # current be1f88abfa5 git checkout be1f88abfa505b08bda761317961fef9b79986fe make test TEST="micro:java.lang.StringBuilders.appendWithInt" make test TEST="micro:java.lang.StringBuilders.appendWithLong" ## 2. aliyun_ecs_c8a_x64 (CPU AMD EPYC™ Genoa) -Benchmark Mode Cnt Score Error Units (d9e4383cca7) -StringBuilders.appendWithIntLatin1 avgt 15 171.264 ± 2.500 ns/op -StringBuilders.appendWithIntUtf16 avgt 15 162.430 ± 1.829 ns/op -StringBuilders.appendWithLongLatin1 avgt 15 227.369 ± 1.452 ns/op -StringBuilders.appendWithLongUtf16 avgt 15 214.854 ± 0.495 ns/op +Benchmark Mode Cnt Score Error Units (be1f88abfa5) +StringBuilders.appendWithIntLatin1 avgt 15 136.149 ± 0.213 ns/op +25.79% +StringBuilders.appendWithIntUtf16 avgt 15 165.650 ± 0.762 ns/op -1.94% +StringBuilders.appendWithLongLatin1 avgt 15 190.156 ± 2.260 ns/op +19.56% +StringBuilders.appendWithLongUtf16 avgt 15 224.880 ± 0.389 ns/op -4.45% ## 3. aliyun_ecs_c8i_x64 (CPU Intel®Xeon®Emerald Rapids) -Benchmark Mode Cnt Score Error Units (d9e4383cca7) -StringBuilders.appendWithIntLatin1 avgt 15 176.098 ± 3.122 ns/op -StringBuilders.appendWithIntUtf16 avgt 15 162.548 ± 0.403 ns/op -StringBuilders.appendWithLongLatin1 avgt 15 225.868 ± 1.912 ns/op -StringBuilders.appendWithLongUtf16 avgt 15 201.952 ± 6.429 ns/op +Benchmark Mode Cnt Score Error Units (be1f88abfa5) +StringBuilders.appendWithIntLatin1 avgt 15 145.052 ± 0.633 ns/op +21.40% +StringBuilders.appendWithIntUtf16 avgt 15 166.678 ± 0.392 ns/op -2.47% +StringBuilders.appendWithLongLatin1 avgt 15 187.617 ± 1.750 ns/op +20.38% +StringBuilders.appendWithLongUtf16 avgt 15 214.047 ± 1.687 ns/op -5.65% ## 4. aliyun_ecs_c8y_aarch64 (CPU Aliyun Yitian 710 ARM v9) -Benchmark Mode Cnt Score Error Units (d9e4383cca7) -StringBuilders.appendWithIntLatin1 avgt 15 267.675 ± 0.180 ns/op -StringBuilders.appendWithIntUtf16 avgt 15 246.470 ± 0.896 ns/op -StringBuilders.appendWithLongLatin1 avgt 15 342.262 ± 0.292 ns/op -StringBuilders.appendWithLongUtf16 avgt 15 327.840 ± 0.565 ns/op +Benchmark Mode Cnt Score Error Units (be1f88abfa5) +StringBuilders.appendWithIntLatin1 avgt 15 239.923 ± 1.331 ns/op +11.56% +StringBuilders.appendWithIntUtf16 avgt 15 252.083 ± 2.270 ns/op -2.22% +StringBuilders.appendWithLongLatin1 avgt 15 294.602 ± 2.770 ns/op +16.17% +StringBuilders.appendWithLongUtf16 avgt 15 324.465 ± 0.498 ns/op +1.04% ## 5. MacBook M1 Pro (aarch64) -Benchmark Mode Cnt Score Error Units (d9e4383cca7) -StringBuilders.appendWithIntLatin1 avgt 15 183.633 ? 5.675 ns/op -StringBuilders.appendWithIntUtf16 avgt 15 156.111 ? 1.045 ns/op -StringBuilders.appendWithLongLatin1 avgt 15 246.320 ? 0.934 ns/op -StringBuilders.appendWithLongUtf16 avgt 15 222.053 ? 1.177 ns/op +Benchmark Mode Cnt Score Error Units (be1f88abfa5) +StringBuilders.appendWithIntLatin1 avgt 15 139.442 ? 0.488 ns/op +31.69% +StringBuilders.appendWithIntUtf16 avgt 15 155.319 ? 1.039 ns/op +0.50% +StringBuilders.appendWithLongLatin1 avgt 15 202.335 ? 2.133 ns/op +21.73% +StringBuilders.appendWithLongUtf16 avgt 15 223.250 ? 0.774 ns/op -0.53% ## 6. orange_pi5_aarch64 (CPU RK3588S ARMv8.4) -Benchmark Mode Cnt Score Error Units (d9e4383cca7) -StringBuilders.appendWithIntLatin1 avgt 15 460.837 ± 6.925 ns/op -StringBuilders.appendWithIntUtf16 avgt 15 482.623 ± 16.269 ns/op -StringBuilders.appendWithLongLatin1 avgt 15 653.808 ± 15.051 ns/op -StringBuilders.appendWithLongUtf16 avgt 15 619.189 ± 15.581 ns/op +Benchmark Mode Cnt Score Error Units +StringBuilders.appendWithIntLatin1 avgt 15 385.403 ± 5.387 ns/op +19.57% +StringBuilders.appendWithIntUtf16 avgt 15 439.273 ± 3.404 ns/op +9.86% +StringBuilders.appendWithLongLatin1 avgt 15 573.817 ± 20.499 ns/op +13.94% +StringBuilders.appendWithLongUtf16 avgt 15 661.942 ± 0.282 ns/op -6.45% ------------- PR Comment: https://git.openjdk.org/jdk/pull/22023#issuecomment-2602801895