RFR: 8347009: Speed up parseInt and parseLong [v3]
Shaojin Wen
swen at openjdk.org
Sat Jan 4 12:26:38 UTC 2025
On Sat, 4 Jan 2025 12:09:04 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:
>
> use String::value
Below are the performance numbers on each platform
## 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 9ea084555792fb3c870f6393ce53873e9bde73e6
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
-Longs.parseLong 500 avgt 15 3.542 ± 0.022 us/op
-Integers.parseInt 500 avgt 15 3.269 ± 0.015 us/op
+Benchmark (size) Mode Cnt Score Error Units
+Longs.parseLong 500 avgt 15 3.240 ± 0.037 us/op +9.32%
+Integers.parseInt 500 avgt 15 3.208 ± 0.004 us/op +1.90%
## 3. aliyun_ecs_c8i_x64 (CPU Intel®Xeon®Emerald Rapids)
-Benchmark (size) Mode Cnt Score Error Units
-Longs.parseLong 500 avgt 15 3.477 ± 0.009 us/op
-Integers.parseInt 500 avgt 15 3.138 ± 0.006 us/op
+Benchmark (size) Mode Cnt Score Error Units
+Longs.parseLong 500 avgt 15 3.023 ± 0.028 us/op +15.01%
+Integers.parseInt 500 avgt 15 2.847 ± 0.005 us/op +10.22%
## 4. aliyun_ecs_c8y_aarch64 (CPU Aliyun Yitian 710 ARM)
-Benchmark (size) Mode Cnt Score Error Units
-Longs.parseLong 500 avgt 15 3.819 ± 0.044 us/op
-Integers.parseInt 500 avgt 15 3.639 ± 0.075 us/op
+Benchmark (size) Mode Cnt Score Error Units
+Longs.parseLong 500 avgt 15 3.347 ± 0.015 us/op +14.10%
+Integers.parseInt 500 avgt 15 3.192 ± 0.010 us/op +14.03%
## 5. MacBook M1 Pro (aarch64)
-Benchmark (size) Mode Cnt Score Error Units
-Longs.parseLong 500 avgt 15 2.608 ? 0.035 us/op
-Integers.parseInt 500 avgt 15 2.325 ? 0.005 us/op
+Benchmark (size) Mode Cnt Score Error Units
+Longs.parseLong 500 avgt 15 2.291 ? 0.018 us/op +13.83%
+Integers.parseInt 500 avgt 15 2.079 ? 0.011 us/op +11.83%
-------------
PR Comment: https://git.openjdk.org/jdk/pull/22919#issuecomment-2571272942
More information about the core-libs-dev
mailing list