8229845: Decrease memory consumption of BigInteger.toString()
ivan.gerasimov at oracle.com
Tue Aug 20 21:45:53 UTC 2019
Would it make sense to add an argument `digits` to smallToString (like
the same named argument of toString, the minimum number of digits to pad
to), so it could zero-pad the result itself?
This way we could avoid inserting zeros into the middle of a
StringBuilder after a call to smallToString.
With kind regards,
On 8/20/19 11:51 AM, Brian Burkhalter wrote:
> Delta  and revised  patches:
>  http://cr.openjdk.java.net/~bpb/8229845/webrev.00-01/
>  http://cr.openjdk.java.net/~bpb/8229845/webrev.01/
>> On Aug 20, 2019, at 1:05 AM, Aleksey Shipilev <shade at redhat.com
>> <mailto:shade at redhat.com>> wrote:
>> On 8/19/19 10:08 PM, Brian Burkhalter wrote:
>> 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 <mailto: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.
With kind regards,
More information about the core-libs-dev