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

Roger Riggs rriggs at openjdk.org
Mon Jan 26 23:41:25 UTC 2026


On Fri, 23 Jan 2026 03:42:47 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:
> 
>   from @liach

src/java.base/share/classes/java/lang/Integer.java line 496:

> 494:         }
> 495:         int len;
> 496:         if ((len = s.length()) == 0) {

`parseInt(s, begiNIndex, endIndex, radix)` already checks for an empty string and calls `NumberformatException.forInputString("", radix)`
See Integer:555.

src/java.base/share/classes/java/lang/Long.java line 531:

> 529:         if ((len = s.length()) == 0) {
> 530:             throw NumberFormatException.forInputString(s);
> 531:         }

Duplicate check for empty string, already checked in Long:583.

src/java.base/share/classes/java/lang/NumberFormatException.java line 58:

> 56: 
> 57:     /**
> 58:      * Factory method for making a {@code NumberFormatException}

Should document it is for radix = 10.
This method doesn't add much value over calling the version with the radix.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22919#discussion_r2729632002
PR Review Comment: https://git.openjdk.org/jdk/pull/22919#discussion_r2729683484
PR Review Comment: https://git.openjdk.org/jdk/pull/22919#discussion_r2729690061


More information about the core-libs-dev mailing list