[Mono-devel-list] StringBuilder patch

Torstensson, Patrik patrik.torstensson at intel.com
Fri Dec 12 10:13:13 EST 2003


Hi,

I have attached a patch that optimizes our implementation of
StringBuilder, it contains changes in marshalling due to changes in the
internal StringBuilder format, changes to String.cs and
StringBuilder.cs.

The new StringBuilder.cs works more like the Microsoft StringBuilder and
uses memory in a more effictive way. Some of the main differences is -:

- Uses a String directly as buffer
- Reallocates string buffer only when ToString has been called on a
buffer filled more than 50%
- Keeps internal length/capacity and sets the string length during call
to ToString()

Some numbers:

500.000 creation of StringBuilder and 2 appends for each string builder
of 5 and 6 chars.

Before:	55644 KB
New:		38086 KB

500.000 calls to two appends with setting length to 0 after the two
appends (same stringbuilder) 
(the old StringBuilder was optimial for this case due to it never needed
to reallocate the internal buffer)

Before:	49805 KB
New:		49805 KB

Build of MCS:
(MCS reuses StringBuilder a lot)

Before:	60771 KB
New:		60580 KB

Build of corlib:

Before:	174818 KB
New:		173829 KB

As you can see MCS is good at reusing StringBuilder's, I haven't tested
it on something that uses StringBuilder heavily (like System.XML) but it
would be good to do that also. Overall timing says that the new version
is a bit faster.

Please review it as soon as possible, it would be good to get it into
CVS.

Cheers,
 Patrik Torstensson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: corlib.diff
Type: application/octet-stream
Size: 33123 bytes
Desc: corlib.diff
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20031212/e5887c6a/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: metadata.diff
Type: application/octet-stream
Size: 1555 bytes
Desc: metadata.diff
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20031212/e5887c6a/attachment-0001.obj 


More information about the Mono-devel-list mailing list