[Mono-devel-list] Re: [Mono-patches] r46353 - trunk/mcs/class/System.XML/System.Xml
bmaurer at ximian.com
Wed Jun 22 13:59:33 EDT 2005
On Wed, 2005-06-22 at 04:12 -0400, Atsushi Enomoto
(ginga at kit.hi-ho.ne.jp) wrote:
> Author: atsushi
> Date: 2005-06-22 04:12:53 -0400 (Wed, 22 Jun 2005)
> New Revision: 46353
> 2005-06-22 Atsushi Enomoto <atsushi at ximian.com>
> * XmlTextReader.cs : use StringBuilder to store character values; that
> saves 40% memory for large chunk of xml. Patch by Gonzalo.
> Don't remove ChangeLog entry BTW.
> Modified: trunk/mcs/class/System.XML/System.Xml/ChangeLog
> --- trunk/mcs/class/System.XML/System.Xml/ChangeLog 2005-06-22 07:50:13 UTC (rev 46352)
> +++ trunk/mcs/class/System.XML/System.Xml/ChangeLog 2005-06-22 08:12:53 UTC (rev 46353)
> @@ -1,3 +1,8 @@
> +2005-06-22 Atsushi Enomoto <atsushi at ximian.com>
> + * XmlTextReader.cs : use StringBuilder to store character values; that
> + saves 40% memory for large chunk of xml. Patch by Gonzalo.
I think this needs to be changed to make it optimal for the normal case.
Gonzalo's situation is a corner case: 1 huge field in the middle of tons
of stuff. However, normally, there are many, small, similarly sized
fields. So what happens is that the string builder does the standard
"double when there is too much data". Most strings will end up being (on
average) 25% larger than they need to be.
Therefore, we should do something like this:
if (sb.Capacity < 100)
return sb.Substring (0, sb.Length);
return sb.ToString ();
That way, if the string is small, "substring" will be used. It will
create a string of the exact size we want. The stringbuilder buffer can
then be reused.
More information about the Mono-devel-list