RFR: 8347009: Speed up parseInt and parseLong [v6]
Raffaello Giulietti
rgiulietti at openjdk.org
Fri Jan 24 19:41:47 UTC 2025
On Tue, 14 Jan 2025 15:53:36 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:
>
> - remove unused
> - Update src/java.base/share/classes/jdk/internal/util/DecimalDigits.java
>
> Co-authored-by: Chen Liang <liach at openjdk.org>
I might be wrong, but I think that `&&` are compiled down to conditionals?
The code optimistically assumes that the string is parsable as an `int|long`, so `&` might lead to simpler machine code.
Of course, if the benchmarks are good with `&&`, then please feel free to replace.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/22919#issuecomment-2613253311
More information about the core-libs-dev
mailing list