RFR: 8347009: Speed ​​up parseInt and parseLong [v16]

Raffaello Giulietti rgiulietti at openjdk.org
Wed Feb 5 14:06:19 UTC 2025


On Wed, 5 Feb 2025 12:58:49 GMT, Shaojin Wen <swen at openjdk.org> wrote:

>> This is an optimization for decimal Integer.parseInt and Long.parseLong, which improves performance by about 10%. The optimization includes:
>> 1. Improve performance by parsing 2 numbers at a time, which has performance improvements for numbers with length >= 3.
>> 2. It uses charAt(0) for the first number. Assuming that the optimization can eliminate boundary checks, this will be more friendly to parsing numbers with length 1.
>> 3. It removes the reliance on the Character.digit method and eliminates the reliance on the CharacterDataLatin1#DIGITS cache array, which avoids performance degradation caused by cache misses.
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
> 
>   copyright

src/java.base/share/classes/jdk/internal/util/DecimalDigits.java line 138:

> 136: 
> 137:     /**
> 138:      * Determine whether the two strings in bytes are both numbers. If they are, return d0 * 10 + d1, otherwise return -1

This is confusing: two strings?
Also, "digits" would be better than "numbers".
Finally, d0 and d1 are not defined here.

src/java.base/share/classes/jdk/internal/util/DecimalDigits.java line 144:

> 142:      */
> 143:     @ForceInline
> 144:     public static int digit2(byte[] str, int offset) {

Suggestion:

    public static int digit2(byte[] str, int offset) {
        // Used by trusted callers.  Assumes all necessary bounds checks have been done by the caller.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22919#discussion_r1943003191
PR Review Comment: https://git.openjdk.org/jdk/pull/22919#discussion_r1943003383


More information about the core-libs-dev mailing list