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

Shaojin Wen duke at openjdk.org
Thu Oct 12 09:58:19 UTC 2023


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

>> Let's not forget that `Character.digit()` has a pretty decent fast path for Latin1, including a 256 bytes lookup-table.
>
> 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

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

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


More information about the core-libs-dev mailing list