[ 
https://issues.apache.org/jira/browse/IGNITE-11911?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16861549#comment-16861549
 ] 

Ignite TC Bot commented on IGNITE-11911:
----------------------------------------

{panel:title=--> Run :: All: No blockers 
found!|borderStyle=dashed|borderColor=#ccc|titleBGColor=#D6F7C1}{panel}
[TeamCity *--> Run :: All* 
Results|https://ci.ignite.apache.org/viewLog.html?buildId=4095191&buildTypeId=IgniteTests24Java8_RunAll]

> GridToStringBuilder allocates redundant memory
> ----------------------------------------------
>
>                 Key: IGNITE-11911
>                 URL: https://issues.apache.org/jira/browse/IGNITE-11911
>             Project: Ignite
>          Issue Type: Bug
>    Affects Versions: 2.7
>            Reporter: Aleksey Plekhanov
>            Assignee: Aleksey Plekhanov
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> A lot of classes in Ignite uses {{GridToStringBuilder}} to implement their 
> {{toString()}} method. {{GridToStringBuilder}} uses thread local buffer to 
> generate string representation. This buffer extended on demand but never 
> shrank. On the final step {{GridToStringBuilder}} uses java {{StringBuilder}} 
> class to produce output string and uses own buffer size as {{StringBuilder}} 
> initial capacity. This leads to unnecessary memory allocation since we only 
> need to allocate memory for meaningful data, but not for all buffer.
>  Reproducer:
>  
> {code:java}
> public void testSB() {
>     GridToStringBuilder.toString(C1.class, new C1(1_000_000));
>     GridToStringBuilder.toString(C1.class, new C1(100));
> }
> public class C1 {
>     private String f;
>     C1(int len) {
>         f = new String(new char[len]);
>     }
> }
> {code}
> Here on the second line about 1 million chars StringBuilder will be 
> allocated, but only about 100 chars needed.
>  
> Problem code (SBLimitedLength.java:293):
>  
> {code:java}
> StringBuilder res = new StringBuilder(impl().capacity() + tailLen + 100);
> {code}
> Here {{length()}} method can be used instead of {{capacity()}}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to