On Sat, 13 Jul 2024 00:50:18 GMT, Shaojin Wen <[email protected]> wrote:
>> Currently, about 25% of the time spent by the Integer.parseInt and
>> Long.parseLong methods is spent on the Character.digit method.
>>
>> The Character.digit method is common to all radixes. We can use a digit
>> method optimized for Latin1 encoding radix 10 to improve the performance of
>> Integer.parseInt and Long.parseLong methods.
>
> Shaojin Wen has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Reduce changes
A straightforward guess would be converting the `Character.digit()` call to a
utility method like:
private static int digit(char ch/*, int radix*/) {
if (ch >= '0' && ch <= '9') // or replace it with something like
Math.min('9', '0' + radix)
return ch - '0'; // ascii base-10 fast path
return digit(ch/*, radix*/);
}
Inspired by this:
https://github.com/openjdk/jdk/blob/ae9f318fc35eeab497e546ebab9faed6ec774ec5/src/java.base/share/classes/jdk/internal/constant/ConstantUtils.java#L236
However I don't know how JIT has compiled the code, so not sure how my
speculative approach works compared to yours. But it is definitely somewhat
less invasive, without the new table and latin1 requirements.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/20168#issuecomment-2226736083