[Mono-list] Profiling web app to find where memory is going

Mike Glenn mglenn at zoominternet.net
Fri Jan 13 09:15:40 EST 2006


I'm not sure if this is related but there are some terrible inefficiencies in
following two classes

mcs/class/corlib/System.IO/TextWriter.cs
mcs/class/System.Web/System.Web/HttpWriter.cs

I've not had a chance to make a patch yet, so I'll explain so someone else can
if they want to get it done before I can. But suffice to say that how one calls
Write on a TextWriter output stream in XSP/Mod_mono can double your
connections/sec (as it did for me)!

It comes down to this method in TextWriter.cs

public virtual void Write (char[] value)
{
	if (value != null) {
		for (int i = 0; i < value.Length; ++i)
			Write (value [i]);
	}
}

Which I think should look like this

public virtual void Write (char[] value)
{
	// No if statement needed since TextWriter is abstract 
	// the implementing class should take care of checking for null.
	Write(value, 0, value.Length);	
}

And then in HttpWriter.cs you have the following method:

public override void Write (char ch)
{
	Write(new string (ch, 1));
}

Which was being called by the TextWriter method at the top and was causing a
class creation explosion. I'm not sure what's the best way to fix this method
but by calling the Write(char[] c, int index, int count) instead I was able to
double the connections/sec for my app on XSP.

Mike Glenn





 




More information about the Mono-list mailing list