> 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 21 additional commits since the last revision: - Merge remote-tracking branch 'upstream/master' into optim_dec_new - use while instead for - Update src/java.base/share/classes/java/math/BigDecimal.java Co-authored-by: Claes Redestad <claes.redes...@oracle.com> - bug fix for CharArraySequence#charAt - bug fix for CharArraySequence - fix benchmark - one CharArraySequence - restore comment - easier to compare - fix CharArraySequence - ... and 11 more: https://git.openjdk.org/jdk/compare/886ef758...e516b580 ------------- Changes: - all: https://git.openjdk.org/jdk/pull/18177/files - new: https://git.openjdk.org/jdk/pull/18177/files/17f0a736..e516b580 Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=18177&range=16 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=18177&range=15-16 Stats: 562957 lines in 6174 files changed: 85928 ins; 137051 del; 339978 mod Patch: https://git.openjdk.org/jdk/pull/18177.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/18177/head:pull/18177 PR: https://git.openjdk.org/jdk/pull/18177