RFR: 8317980: Optimization for Integer.parseInt and Long.parseLong

Shaojin Wen duke at openjdk.org
Thu Oct 12 02:20:49 UTC 2023


On Tue, 10 Oct 2023 02:54:05 GMT, Shaojin Wen <duke at openjdk.org> wrote:

> By extracting the code that creates the exception, the CodeSize of these methods is less than the default FreqInlineSize 325.  and for the scenario where the most commonly used radix is not specified and the String coder is LATIN1, fast-path can improves the performance 10% of parseInt(String)/parseLong(String).

By extracting the code that creates the exception, the CodeSize of these methods is less than the default FreqInlineSize 325.

codeSize 350 bytes -> 260 bytes
public static int parseUnsignedInt(CharSequence s, int beginIndex, int endIndex, int radix)

codeSize 327 bytes -> 283 bytes
public static long parseLong(CharSequence s, int beginIndex, int endIndex, int radix)

codeSize 362 bytes -> 269 bytes
public static long parseUnsignedLong(CharSequence s, int beginIndex, int endIndex, int radix)


Performance numbers running on MacBook M1 Pro:

-Benchmark                              (size)  Mode  Cnt  Score   Error  Units
-Integers.parseInt                         500  avgt   15  2.501 ? 0.028  us/op
-Integers.parseIntCharSequence             500  avgt   15  2.558 ? 0.042  us/op
-Integers.parseUnisgnedIntCharSequence     500  avgt   15  3.883 ? 0.040  us/op
-Integers.parseUnsignedInt                 500  avgt   15  2.266 ? 0.008  us/op
-Longs.parseLong                           500  avgt   15  2.790 ? 0.017  us/op
-Longs.parseLongCharSequence               500  avgt   15  3.779 ? 0.043  us/op
-Longs.parseUnsignedLong                   500  avgt   15  2.421 ? 0.032  us/op
-Longs.parseUnsignedLongCharSequence       500  avgt   15  4.107 ? 0.046  us/op

+Benchmark                              (size)  Mode  Cnt  Score   Error  Units
+Integers.parseInt                         500  avgt   15  2.238 ? 0.017  us/op (+11.76)
+Integers.parseIntCharSequence             500  avgt   15  2.515 ? 0.004  us/op (+1.71)
+Integers.parseUnisgnedIntCharSequence     500  avgt   15  2.274 ? 0.031  us/op (+70.76)
+Integers.parseUnsignedInt                 500  avgt   15  2.265 ? 0.006  us/op (+0.05)
+Longs.parseLong                           500  avgt   15  2.492 ? 0.023  us/op (+11.96)
+Longs.parseLongCharSequence               500  avgt   15  2.807 ? 0.031  us/op (+34.63)
+Longs.parseUnsignedLong                   500  avgt   15  2.404 ? 0.047  us/op (+0.71)
+Longs.parseUnsignedLongCharSequence       500  avgt   15  2.379 ? 0.025  us/op (+72.64)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/16112#issuecomment-1754259343


More information about the core-libs-dev mailing list