RFR: 8347009: Speed up parseInt and parseLong [v17]
Raffaello Giulietti
rgiulietti at openjdk.org
Wed Feb 5 16:51:14 UTC 2025
On Wed, 5 Feb 2025 16:21: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 two additional commits since the last revision:
>
> - fix comments
> - Update src/java.base/share/classes/jdk/internal/util/DecimalDigits.java
>
> Co-authored-by: Raffaello Giulietti <raffaello.giulietti at oracle.com>
src/java.base/share/classes/jdk/internal/util/DecimalDigits.java line 138:
> 136:
> 137: /**
> 138: * Determine whether the two character in str are both digits. If they are, return (str[off] - '0') * 10 + (str[off] - '0'), otherwise return -1
`off` -> `offset`
The second index should be `offset + 1`.
Same in the `@return` clause.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22919#discussion_r1943313957
More information about the core-libs-dev
mailing list