RFR: 8347009: Speed up parseInt and parseLong [v11]
Johannes Graham
duke at openjdk.org
Wed Jan 29 18:49:47 UTC 2025
On Wed, 29 Jan 2025 16:30:46 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 181:
> 179: return -1;
> 180: }
> 181: return ((d & 0xF) << 3) + ((d & 0xF) << 1) // (d & 0xF) * 10
Is simply using `(d & 0xF) * 10` any worse? I expect the compiler knows this trick and would use it when appropriate.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22919#discussion_r1934408496
More information about the core-libs-dev
mailing list