RFR: 8315585: Optimization for new BigDecimal(String)
Shaojin Wen
duke at openjdk.org
Mon Mar 11 11:15:14 UTC 2024
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..
-------------
Commit messages:
- fix code style
- optimization for new BigDecimal(char[])
- optimization for new BigDecimal(String)
Changes: https://git.openjdk.org/jdk/pull/18177/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18177&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8315585
Stats: 407 lines in 4 files changed: 331 ins; 29 del; 47 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
More information about the core-libs-dev
mailing list