From 4cf9a7a9648ce55889e23dd140fdb7b43cb0f3ee Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 4 Apr 2023 15:36:29 -0700 Subject: [PATCH] Fix #967 --- release-notes/VERSION-2.x | 1 + .../com/fasterxml/jackson/core/io/BigDecimalParser.java | 9 ++++++++- .../jackson/failing/PerfBigDecimalParser967.java | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 99e3bc448a..939ac3ddbb 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -25,6 +25,7 @@ No changes since 2.14 #912: Optional padding Base64Variant still throws exception on missing padding character (reported by @Vity01) +#967: Address performance issue with `BigDecimalParser` 2.14.2 (28-Jan-2023) diff --git a/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java b/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java index 173af8300e..1afba6d0d6 100644 --- a/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java +++ b/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java @@ -178,6 +178,13 @@ private static BigDecimal toBigDecimalRec(final char[] chars, final int off, fin return left.add(right); } - return len == 0 ? BigDecimal.ZERO : new BigDecimal(chars, off, len).movePointRight(scale); + if (len == 0) { + return BigDecimal.ZERO; + } + // 02-Apr-2023, tatu: [core#967] Looks like "scaleByPowerOfThen" avoids performance issue + // there would be with "movePointRight" (both doing about same thing), so) + return new BigDecimal(chars, off, len) +// .movePointRight(scale); + .scaleByPowerOfTen(scale); } } diff --git a/src/test/java/com/fasterxml/jackson/failing/PerfBigDecimalParser967.java b/src/test/java/com/fasterxml/jackson/failing/PerfBigDecimalParser967.java index d57cdc0b7c..42e7f6d8fd 100644 --- a/src/test/java/com/fasterxml/jackson/failing/PerfBigDecimalParser967.java +++ b/src/test/java/com/fasterxml/jackson/failing/PerfBigDecimalParser967.java @@ -11,7 +11,7 @@ public class PerfBigDecimalParser967 private final JsonFactory JSON_F = new JsonFactory(); // For [core#967]: shouldn't take multiple seconds - @Test(timeout = 35000) + @Test(timeout = 3000) public void bigDecimalFromString() throws Exception { // Jackson's BigDecimalParser seems to be slower than JDK's; // won't fail if using latter.