RFR: 8355177: Speed up StringBuilder::append(char[]) via UTF16::compress & Unsafe::copyMemory [v4]
Roger Riggs
rriggs at openjdk.org
Fri May 2 17:35:53 UTC 2025
On Fri, 2 May 2025 03:49:39 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> In BufferedReader.readLine and other similar scenarios, we need to use StringBuilder.append(char[]) to build the string.
>>
>> For these scenarios, we can use the intrinsic method StringUTF16.compress and Unsafe.copyMemory instead of the character copy of the char-by-char loop to improve the speed.
>
> Shaojin Wen has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains seven commits:
>
> - Merge remote-tracking branch 'upstream/master' into optim_sb_append_chars_202504
>
> # Conflicts:
> # src/java.base/share/classes/java/lang/AbstractStringBuilder.java
> - Merge remote-tracking branch 'upstream/master' into optim_sb_append_chars_202504
>
> # Conflicts:
> # src/java.base/share/classes/java/lang/StringUTF16.java
> - putCharsUnchecked
> - copyright
> - Using StringUTF16.compress to speed up LATIN1 StringBuilder append(char[])
> - Using Unsafe.copyMemory to speed up UTF16 StringBuilder append(char[])
> - add append(char[]) benchmark
Changes requested by rriggs (Reviewer).
src/java.base/share/classes/java/lang/StringUTF16.java line 1322:
> 1320: val,
> 1321: Unsafe.ARRAY_BYTE_BASE_OFFSET + ((long) index << 1),
> 1322: ((long) (end - off)) << 1);
This use of Unsafe is not warranted. If it can't be done with arrayCopy, leave the original code as is.
-------------
PR Review: https://git.openjdk.org/jdk/pull/24773#pullrequestreview-2812557629
PR Review Comment: https://git.openjdk.org/jdk/pull/24773#discussion_r2071937012
More information about the core-libs-dev
mailing list