8229845: Decrease memory consumption of BigInteger.toString()
brian.burkhalter at oracle.com
Tue Aug 20 18:51:19 UTC 2019
Delta  and revised  patches:
 http://cr.openjdk.java.net/~bpb/8229845/webrev.00-01/ <http://cr.openjdk.java.net/~bpb/8229845/webrev.00-01/>
> On Aug 20, 2019, at 1:05 AM, Aleksey Shipilev <shade at redhat.com> wrote:
> On 8/19/19 10:08 PM, Brian Burkhalter wrote:
>>  http://cr.openjdk.java.net/~bpb/8229845/webrev.00/ <http://cr.openjdk.java.net/~bpb/8229845/webrev.00/>
> Two drive-by comments:
> *) It seems the "signum == 0" case in smallToString is regressing? Before, it just returned the
> constant-pooled "0", now it goes via StringBuilder;
Yes, and I don’t see any way not to have it do so. Note that due to lines 3933-3936 in  this case will never be hit for values which have no more than 20 ints in their magnitude, i.e., those which do not recurse in toString(BigInteger,StringBuilder,int,int).
> *) This might be "static final", while we are at it:
> 4109 private static String zeros = new String;
Above made final at L4111 in .
> On Aug 20, 2019, at 10:28 AM, Ivan Gerasimov <ivan.gerasimov at oracle.com> wrote:
> While we're here.
> On 8/20/19 1:05 AM, Aleksey Shipilev wrote:
>> *) This might be "static final", while we are at it:
>> 4109 private static String zeros = new String;
> It may make sense to create the only string as
> private static final String zeros = "0".repeat(63);
Changed at L4111 in .
> and then replace all
> sb.append(zeros[x]) with sb.append(zeros, 0, x) and
L4006 in .
> sb.insert(pos, zeros[x]) with sb.insert(pos, zeros, 0, x).
L4049 and L4054 in .
> The difference would be in one extra bounds check, and as both append() and insert() are relatively expensive, this check would hardly be noticeable.
More information about the core-libs-dev