On Tue, 12 Mar 2024 19:09:27 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:
> 
>   one CharArraySequence

test/micro/org/openjdk/bench/java/math/BigDecimals.java line 103:

> 101:             stringInputs[i] = "" + value;
> 102:             stringHugeInputs[i] = "" + -(i + 1) * 5434543453454355e100;
> 103:             stringLargeInputs[i] = "" + -(i + 1) * 5434543453454355e100;

These two are the same?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18177#discussion_r1522286067

Reply via email to