shared "value" in java.lang.StringBuilder

Tom Hawtin tom.hawtin at
Mon Nov 11 19:01:34 UTC 2013

On 06/11/2013 21:54, Robert Stupp wrote:

 > Wouldn't it worth to try whether passing the
 > (Abstract)StringBuilder's value+count values to String results in
 > less temporary object creations and therefore reduce pressure on new
 > generation (and reduce GC effort)? My idea is to add a field 'shared'
 > to AbstractStringBuilder,

Unfortunately that would result in mutable Strings. You also end up with 
overly long Strings, with the extra never getting collected. Even 
StringBuffer with its synchronisation overhead was problematic. In any 
case, the current String drops the offset and length fields for faster 
implementation that uses less memory (if only we could merge the char[] 
into the main object).


More information about the core-libs-dev mailing list