On Sat, 4 Jan 2025 12:09:04 GMT, Shaojin Wen <s...@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: > > use String::value Some other thoughts that might help here; except for leading zeros, 9 (or 18 for a long) or fewer digits cannot overflow. So something like this might work: - read first char and check if it is a sign character. - skip leading zeros - loop over up to 9 digits, performing the calculation without needing to check for overflow. I think it would be enough to do this 1 digit at a time. - If there are any digits left, take only the next digit, and incorporate it into the result while doing the overflow check. - If there are still more digits left it is too big to fit. This approach could also be taken for the more general parse methods. ------------- PR Comment: https://git.openjdk.org/jdk/pull/22919#issuecomment-2571374257