RFR: 8317980: Optimization for Integer.parseInt and Long.parseLong

Chen Liang liach at openjdk.org
Thu Oct 12 10:06:11 UTC 2023


On Thu, 12 Oct 2023 09:55:15 GMT, Shaojin Wen <duke at openjdk.org> wrote:

>> CharacterDataLatin1.digit is for multi-radix, and the performance when radix = 10 is not good enough.
>
> If we reuse CharacterDataLatin1#DIGITS, the performance will be slower, the performance numbers are as follows
> 
> 
> class CharacterDataLatin1 {
>     static int digit(int ch) {
>         int value = DIGITS[ch & 0xFF];
>         return (value >= 0 && value < 10) ? value : -1;
>     }
> }
> 
> 
> 
> Benchmark          (size)  Mode  Cnt  Score   Error  Units (baseline)
> Integers.parseInt     500  avgt   15  2.614 ? 0.003  us/op
> 
> Benchmark          (size)  Mode  Cnt  Score   Error  Units (use CharacterDataLatin1#digit)
> Integers.parseInt     500  avgt   15  2.399 ? 0.008  us/op
> 
> Benchmark          (size)  Mode  Cnt  Score   Error  Units (c3e878a)
> Integers.parseInt     500  avgt   15  2.251 ? 0.010  us/op

Maybe there's something wrong with the `value < radix` check that JIT cannot efficiently optimize it (so `digit <= 9` has a similar performance to `value < 10` in loops). We might have to check the hotspot assembly to find out the reason.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16112#discussion_r1356591852


More information about the core-libs-dev mailing list