RFR: 8347009: Speed up parseInt and parseLong [v5]
Shaojin Wen
swen at openjdk.org
Sun Jan 5 11:42:35 UTC 2025
On Sun, 5 Jan 2025 11:01:18 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:
>
> vector digit2
The performance is improved again by calculating two characters at a time in the DecimalDigit::digit2 method. The performance numbers are as follows:
## 1. Script
git remote add wenshao git at github.com:wenshao/jdk.git
git fetch wenshao
#master
git checkout 5bb9644202a8b961faad02439c95a81ca6862168
make test TEST="micro:java.lang.Longs.parseLong"
make test TEST="micro:java.lang.Integers.parseInt"
# current
git checkout f97093d324fbb7de322c86d52db11cafcff2de87
make test TEST="micro:java.lang.Longs.parseLong"
make test TEST="micro:java.lang.Integers.parseInt"
## 2. aliyun_ecs_c8a_x64 (CPU AMD EPYC™ Genoa)
-Benchmark (size) Mode Cnt Score Error Units (master 5bb9644)
-Longs.parseLong 500 avgt 15 3.539 ± 0.031 us/op
-Integers.parseInt 500 avgt 15 3.270 ± 0.028 us/op
+Benchmark (size) Mode Cnt Score Error Units (current f97093d)
+Longs.parseLong 500 avgt 15 3.029 ± 0.033 us/op +16.83%
+Integers.parseInt 500 avgt 15 3.120 ± 0.004 us/op +4.80%
## 3. aliyun_ecs_c8i_x64 (CPU Intel®Xeon®Emerald Rapids)
-Benchmark (size) Mode Cnt Score Error Units (master 5bb9644)
-Longs.parseLong 500 avgt 15 3.469 ± 0.011 us/op
-Integers.parseInt 500 avgt 15 3.136 ± 0.005 us/op
+Benchmark (size) Mode Cnt Score Error Units (current f97093d)
+Longs.parseLong 500 avgt 15 2.999 ± 0.024 us/op +15.67%
+Integers.parseInt 500 avgt 15 2.819 ± 0.004 us/op +11.24%
## 4. orange_pi5_aarch64 (CPU RK3588S)
-Benchmark (size) Mode Cnt Score Error Units (master 5bb9644)
-Longs.parseLong 500 avgt 15 9.903 ± 0.064 us/op
-Integers.parseInt 500 avgt 15 9.527 ± 0.678 us/op
+Benchmark (size) Mode Cnt Score Error Units (current f97093d)
+Longs.parseLong 500 avgt 15 8.702 ± 1.287 us/op +13.80%
+Integers.parseInt 500 avgt 15 6.117 ± 0.046 us/op +55.74%
# 5. MacBook M1 Pro (aarch64)
-Benchmark (size) Mode Cnt Score Error Units (master 5bb9644)
-Longs.parseLong 500 avgt 15 2.617 ? 0.040 us/op
-Integers.parseInt 500 avgt 15 2.344 ? 0.027 us/op
+Benchmark (size) Mode Cnt Score Error Units (current f97093d)
+Longs.parseLong 500 avgt 15 2.262 ? 0.014 us/op +15.69%
+Integers.parseInt 500 avgt 15 2.033 ? 0.007 us/op +15.29%
-------------
PR Comment: https://git.openjdk.org/jdk/pull/22919#issuecomment-2571595624
More information about the core-libs-dev
mailing list