Speed up Integer.toString with a precomputed cache array of length 1000, use division by 1000, so that each iteration can calculate three digits.
this optimization can also be used in StringBuilder#appent(int) and Long#toString. # Benchmark Result make test TEST="micro:java.lang.Integers.toString*" ## [aliyun_ecs_c8i.xlarge](https://help.aliyun.com/document_detail/25378.html#c8i) * cpu : intel xeon sapphire rapids (x64) ``` diff -Benchmark (size) Mode Cnt Score Error Units (baseline) -Integers.toStringBig 500 avgt 15 6.811 ± 0.016 us/op -Integers.toStringSmall 500 avgt 15 4.794 ± 0.011 us/op -Integers.toStringTiny 500 avgt 15 3.752 ± 0.065 us/op +Benchmark (size) Mode Cnt Score Error Units (PR) +Integers.toStringBig 500 avgt 15 5.164 ± 0.052 us/op +31.89% +Integers.toStringSmall 500 avgt 15 3.844 ± 0.025 us/op +24.71% +Integers.toStringTiny 500 avgt 15 3.453 ± 0.027 us/op +8.65% ### [aliyun_ecs_c8a.xlarge](https://help.aliyun.com/document_detail/25378.html#c8a) * cpu : amd epc genoa (x64) ``` diff -Benchmark (size) Mode Cnt Score Error Units (baseline) -Integers.toStringBig 500 avgt 15 6.762 ± 0.018 us/op -Integers.toStringSmall 500 avgt 15 4.481 ± 0.004 us/op -Integers.toStringTiny 500 avgt 15 2.761 ± 0.012 us/op +Benchmark (size) Mode Cnt Score Error Units (PR) +Integers.toStringBig 500 avgt 15 5.063 ± 0.175 us/op +33.55% +Integers.toStringSmall 500 avgt 15 3.498 ± 0.123 us/op +28.10% +Integers.toStringTiny 500 avgt 15 2.743 ± 0.147 us/op +0.65% ## [aliyun_ecs_c8y.xlarge](https://help.aliyun.com/document_detail/25378.html#c8y) * cpu : aliyun yitian 710 (aarch64) ``` diff -Benchmark (size) Mode Cnt Score Error Units (baseline) -Integers.toStringBig 500 avgt 15 12.081 ± 0.377 us/op -Integers.toStringSmall 500 avgt 15 7.119 ± 0.177 us/op -Integers.toStringTiny 500 avgt 15 6.323 ± 0.239 us/op +Benchmark (size) Mode Cnt Score Error Units (PR) +Integers.toStringBig 500 avgt 15 8.157 ± 0.274 us/op +48.10% +Integers.toStringSmall 500 avgt 15 7.207 ± 0.330 us/op -1.22% +Integers.toStringTiny 500 avgt 15 6.912 ± 0.199 us/op -8.52% ------------- Commit messages: - 8310929: Optimization for Integer.toString Changes: https://git.openjdk.org/jdk/pull/14699/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14699&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8310929 Stats: 159 lines in 1 file changed: 153 ins; 4 del; 2 mod Patch: https://git.openjdk.org/jdk/pull/14699.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/14699/head:pull/14699 PR: https://git.openjdk.org/jdk/pull/14699