RFR: 8343962: [REDO] Move getChars to DecimalDigits [v3]
Shaojin Wen
swen at openjdk.org
Sun Dec 8 13:52:41 UTC 2024
On Sun, 8 Dec 2024 08:51:34 GMT, Shaojin Wen <swen at 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 16 additional commits since the last revision:
>
> - Merge remote-tracking branch 'upstream/master' into int_get_chars_dedup_202411
> - Merge remote-tracking branch 'upstream/master' into int_get_chars_dedup_202411
> - fix unsafe address overflow
> - add benchmark
> - remove comments, from @liach
> - Merge remote-tracking branch 'upstream/master' into int_get_chars_dedup_202410
> - fix Helper
> - fix Helper
> - fix Helper
> - unsafe putByte
> - ... and 6 more: https://git.openjdk.org/jdk/compare/0f95af17...efa6e6b2
Here are the performance numbers for AMD Linux x64:
## script
git remote add wenshao https://github.com/wenshao/jdk.git
git fetch wenshao
# checkout baseline + benchmark
git checkout efa6e6b229b5f49b7080061bd4d293210c3a9e93
make test TEST="micro:java.lang.StringBuilders.appendWithInt"
make test TEST="micro:java.lang.StringBuilders.appendWithLong"
# checkout pr22023
git checkout efa6e6b229b5f49b7080061bd4d293210c3a9e93
make test TEST="micro:java.lang.StringBuilders.appendWithInt"
make test TEST="micro:java.lang.StringBuilders.appendWithLong"
## performance numbers
# baseline
-Benchmark Mode Cnt Score Error Units
-StringBuilders.appendWithIntLatin1 avgt 15 210.151 ± 0.139 ns/op
-StringBuilders.appendWithIntUtf16 avgt 15 221.580 ± 4.940 ns/op
-StringBuilders.appendWithLongLatin1 avgt 15 211.266 ± 2.063 ns/op
-StringBuilders.appendWithLongUtf16 avgt 15 221.391 ± 4.943 ns/op
# pr22023
+Benchmark Mode Cnt Score Error Units
+StringBuilders.appendWithIntLatin1 avgt 15 191.496 ± 1.252 ns/op +9.74%
+StringBuilders.appendWithIntUtf16 avgt 15 222.215 ± 0.150 ns/op -0.25%
+StringBuilders.appendWithLongLatin1 avgt 15 190.951 ± 0.191 ns/op +10.63%
+StringBuilders.appendWithLongUtf16 avgt 15 222.606 ± 0.434 ns/op -0.54%
## Summary
PR #22023 uses Unsafe, and the performance of appendWithIntLatin1/appendWithLongLatin1 scenes has been improved by about 10%. There is no change in appendWithIntUtf16/appendWithLongUtf16.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/22023#issuecomment-2525950747
More information about the core-libs-dev
mailing list