On Mon, 11 Mar 2024 20:41:25 GMT, Shaojin Wen <d...@openjdk.org> wrote:
>> The current BigDecimal(String) constructor calls String#toCharArray, which >> has a memory allocation. >> >> >> public BigDecimal(String val) { >> this(val.toCharArray(), 0, val.length()); // allocate char[] >> } >> >> >> When the length is greater than 18, create a char[] >> >> >> boolean isCompact = (len <= MAX_COMPACT_DIGITS); // 18 >> if (!isCompact) { >> // ... >> } else { >> char[] coeff = new char[len]; // allocate char[] >> // ... >> } >> >> >> This PR eliminates the two memory allocations mentioned above, resulting in >> an approximate 60% increase in performance.. > > Shaojin Wen has updated the pull request incrementally with one additional > commit since the last revision: > > 1. bug fix for CharBuffer catch IndexOutOfBoundsException > 2. reorder if statement > 3. Improve the performance of !isCompact branch src/java.base/share/classes/java/math/BigDecimal.java line 762: > 760: } > 761: > 762: private BigDecimal(CharSequence val, MathContext mc) { Can we move this constructor to before `parseExp`? This way there will be less diff and it will be easier to compare old and new code side-by-side. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/18177#discussion_r1520792359