[Mono-dev] Creating fewer objects (Sys.Xml, Sys.Web)
Joshua Tauberer
tauberer at for.net
Mon Mar 27 18:20:04 EST 2006
Atsushi & Gonzalo (and anyone else),
Attached are two patches to reduce new object creations.
In Sys.Xml, I cut out string concatenations in XmlElement.Name and
XmlAttribute.Name. The (prefix + ":" + localname) concatenation
occurred even if the final string was already in the NameTable. To
avoid this, I added a method to NameTable (an internal class) to accept
a prefix and localname separately for checking if the final concatenated
string would be in the name table already. The only performance hits
might come from calls to the 'is' operator and two calls to
String.CompareOrdinal rather than a single call to Equals.
In Sys.Web.HttpWriter, a byte[] is created on each call to Write for
strings and char arrays. Instead, I reuse and resize a byte[] array
kept by the class. Since HttpWriter isn't thread safe, this seems ok.
The downside is that string encoding is done through two calls, once to
get the byte count and then to get the bytes. I don't know what kind of
performance impact that might have.
These changes reduce the two biggest object allocators per request for
my ASP.NET site. My hope is that this will cut down on the runaway
memory allocation that I'm still facing and hopefully have no
significant performance cost. But I don't know about either.
I'll try the patches out for a while to make sure I didn't goof anything up.
Thanks guys.
--
- Joshua Tauberer
http://taubz.for.net
"Unfortunately, we're having this discussion. It's too bad,
because guess who listens to the discussion: the enemy."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bytes.sysweb.diff
Type: text/x-patch
Size: 2558 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060327/dbf846aa/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strings.sysxml.diff
Type: text/x-patch
Size: 3969 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060327/dbf846aa/attachment-0001.bin
More information about the Mono-devel-list
mailing list