RFR: 8315585: Optimization for decimal to string [v7]
Shaojin Wen
duke at openjdk.org
Thu Oct 19 11:41:47 UTC 2023
On Wed, 18 Oct 2023 15:59:31 GMT, Claes Redestad <redestad at openjdk.org> wrote:
>> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Use StringConcatFactory.makeConcatWithConstants
>
> I've opened up #16244 for review - thanks for helping with analysis and verification.
@cl4es
> Good, narrows it down to what's going on in `prepend(long, byte[], String)`. Might boil down to `System.arraycopy`. This method might not be optimized for tiny arrays on all platforms. Specializing for single-char case:
>
> ```java
> diff --git a/src/java.base/share/classes/java/lang/String.java b/src/java.base/share/classes/java/lang/String.java
> index 9b19d7e2ac1..6eb70925dab 100644
> --- a/src/java.base/share/classes/java/lang/String.java
> +++ b/src/java.base/share/classes/java/lang/String.java
> @@ -4723,7 +4723,11 @@ static void repeatCopyRest(byte[] buffer, int offset, int limit, int copied) {
> */
> void getBytes(byte[] dst, int dstBegin, byte coder) {
> if (coder() == coder) {
> - System.arraycopy(value, 0, dst, dstBegin << coder, value.length);
> + if (value.length == 1) {
> + dst[(dstBegin << coder)] = value[0];
> + } else {
> + System.arraycopy(value, 0, dst, dstBegin << coder, value.length);
> + }
> } else { // this.coder == LATIN && coder == UTF16
> StringLatin1.inflate(value, 0, dst, dstBegin, value.length);
> }
> ```
>
> .. seem to help the JIT do the right thing consistently, too:
>
> ```
> Benchmark Mode Cnt Score Error Units
> BigDecimals.testSmallToEngineeringString avgt 50 11,757 ± 0,480 ns/op
> ```
In addition to #16244, will you submit a PR for this?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16006#issuecomment-1770715334
More information about the core-libs-dev
mailing list