RFR: 8278831: Use table lookup for the last two bytes in Integer.getChars

Jim Laskey jlaskey at openjdk.java.net
Thu Dec 16 10:42:54 UTC 2021


On Wed, 15 Dec 2021 23:04:37 GMT, Claes Redestad <redestad at openjdk.org> wrote:

> During TemplatedStrings work Jim has noticed that we could probably profit from reusing the lookup tables also for the 1 or 2 leftmost bytes:
> 
>         // We know there are at most two digits left at this point.
>         buf[--charPos] = DigitOnes[-i];
>         if (i < -9) {
>             buf[--charPos] = DigitTens[-i];
>         }
> 
> This avoids some arithmetic, and on average achieves a small speed-up since the lookup tables are likely cached are likely to be in cache. Small improvements on a few affected microbenchmarks, including the new Integers.toStringTiny, can be observed. 
> 
> Baseline:
> 
> Benchmark              (size)  Mode  Cnt   Score   Error  Units
> Integers.toStringTiny     500  avgt   50  21.862 ± 0.211  us/op
> 
> 
> Patch:
> 
> Benchmark              (size)  Mode  Cnt   Score   Error  Units
> Integers.toStringTiny     500  avgt   50  20.619 ± 0.330  us/op

Marked as reviewed by jlaskey (Reviewer).

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

PR: https://git.openjdk.java.net/jdk/pull/6854


More information about the core-libs-dev mailing list