Skip to content

Commit 079a81b

Browse files
authored
Fix #967 (#973): BigDecimalParser performance for edge cases
1 parent 99331c6 commit 079a81b

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ JSON library.
5151
#912: Optional padding Base64Variant still throws exception on missing
5252
padding character
5353
(reported by @Vity01)
54+
#967: Address performance issue with `BigDecimalParser`
5455

5556
2.14.2 (28-Jan-2023)
5657

src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ private static BigDecimal toBigDecimalRec(final char[] chars, final int off, fin
202202
return left.add(right);
203203
}
204204

205-
return len == 0 ? BigDecimal.ZERO : new BigDecimal(chars, off, len).movePointRight(scale);
205+
if (len == 0) {
206+
return BigDecimal.ZERO;
207+
}
208+
// 02-Apr-2023, tatu: [core#967] Looks like "scaleByPowerOfThen" avoids performance issue
209+
// there would be with "movePointRight" (both doing about same thing), so)
210+
return new BigDecimal(chars, off, len)
211+
// .movePointRight(scale);
212+
.scaleByPowerOfTen(scale);
206213
}
207214
}

src/test/java/com/fasterxml/jackson/failing/PerfBigDecimalParser967.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class PerfBigDecimalParser967
1111
private final JsonFactory JSON_F = new JsonFactory();
1212

1313
// For [core#967]: shouldn't take multiple seconds
14-
@Test(timeout = 35000)
14+
@Test(timeout = 3000)
1515
public void bigDecimalFromString() throws Exception {
1616
// Jackson's BigDecimalParser seems to be slower than JDK's;
1717
// won't fail if using latter.

0 commit comments

Comments
 (0)